4 ms·
> People don't like Lua Who doesn't like Lua? That is right up there next to disliking kittens and puppies...
by krylon 4y ago
> People don't like Lua
Who doesn't like Lua? That is right up there next to disliking kittens and puppies...
- azangru 4y agoArrays start at 1?
- oblio 4y agoJust like in math, and Lua doesn't do manual memory management so aligning stuff with memory addresses is not needed. They're both valid options and it's just about preference.
- layer8 4y agoThere are good reasons for zero-based indexing outside of pointer arithmetics: https://www.cs.utexas.edu/users/EWD/transcriptions/EWD08xx/EWD831.html https://www.cs.utexas.edu/users/EWD/transcriptions/EWD08xx/E...
- int_19h 4y agoIt's a well-known argument. It's also widely recognized as highly subjective, starting with the notion that upper bound must be exclusive.
- threatofrain 4y ago> Just like in math I might be wrong, but I think math favors different starting indices based on the subject matter. I've seen Analysis textbooks favor 0 as the starting index. I don't think there's a clear argument for cultural transference from math. I'm opposed to starting index from 1 because I think departure from very mainstream programming tradition should have a strong reason beyond preference, even if the de facto tradition appears equally capricious.
- xigoi 4y agoIndexing starts at 1 in math mostly because in history, people were afraid of 0, and it's hard to change conventions.
- oblio 4y agoDebatable. It makes sense to say "the first element", regardless of mathematical connotations. We've had this kind of expression in almost every language across the world long before we invented multiplication. Saying the "the zeroth element" is just... weird and slightly nonsensical.
- xigoi 4y agoYes, because language developed at a time where people didn't know about zero.
- oblio 4y agoZero still would most likely wooldn't make sense. Zero is nothing, it can't be anything. Even ordinally. 1 is something and it fits very well for the first position... outside of programming :-)
- xigoi 4y agoIn 1-based indexing, the index of an item is the number of items you've already seen, including the one you're looking at. In 0-based indexing, the index of an item is the number of items you've already seen, excluding the one you're looking at.
- krylon 4y agoI agree that is very weird at first. But after building a toy project including about 5,000 lines of Lua, I can say I got used to it fairly quickly. Most of the time, I was accessing arrays via iterators anyway, so I had to deal with indices very rarely. Aesthetically, it is repulsive, but when actually writing code in Lua, it was not much of a problem. I felt much stronger about "do"/"then" and "end" versus curly braces for delimiting blocks.
- usrbinbash 4y agoArray index starts at 1 ~= instead of != # instead of len() Default declaration to global -- for comments Dereferencing something that doesn't exist returns nil