3 ms·
I'm a strong supporter of zero-based arrays (I grew up with C and for me zero-based indexing just seems natural and elegant), but in using Lua, which has one-ba
by snogglethorpe 13y ago
I'm a strong supporter of zero-based arrays (I grew up with C and for me zero-based indexing just seems natural and elegant), but in using Lua, which has one-based arrays, I've found I don't really mind at all.
I think the crucial difference is that Lua doesn't have the emphasis on pointers and address-arithmetic that C does. Zero-based array calculations are really useful for that, but for simpler array usage, either style seems to work fine.
So while I still favor zero-based indexing, I think the context matters a lot, and one-based indexing is not always a problem.
- yogo 13y agoI don't think it's a problem. In fact, when I found myself hung up something as inconsequential as indexing, I question my own rationality. That's why I called it brainwashing because c, c++, javascript, php, java, python,... most of the top 10 languages use 0-based indexing and most likely we would all be comfortable if they had all taken the path of being 1-based. It's sort of like driving on the left or on the right. You just get used to one and you think it's the right side :).
- snogglethorpe 13y agoSure, I know that much of this is "learned preference." What surprised me is that even that didn't actually seem to be a problem in practice [for me], even when frequently switching between zero-based (C++) and one-based (Lua) languages...