As for indexing from zero, it's best understood as indexing the position just before elements in an array. Where things will be inserted if you insert an element etc...
As for indexing from zero, it's best understood as indexing the position just before elements in an array. Where things will be inserted if you insert an element etc...
var item = my_array[2]
should be read as
"assign to item the value in my_array in the position where you would place something new just before the third item"
1-indexing is, strictly speaking, a better design. The only real argument for it anymore in a higher level language is "it's what I'm used to", or alternatively, "0 already won the popularity contest" (which is actually not a terrible argument in context, though it is a bad one from a purely objective design perspective).
How do you access the item in a 2D array represented on a flat array? my_array[x+ywidth]
But what is all that starts at 1? my_array[x+(y-1)width]
I did a lot of code in both systems and I remember distinctly that 1.. indexing just was more work to do, in turn bringing in more off by 1 bugs.
Depends on what you are doing. I seldom have to do a flat 2D array these days, but array[total-1] is an almost everyday thing.
Idiomatic Lua code for tables doesn't run into the kind of edge cases Dijkstra presents, since the most readable code uses iterators to yield the values of array indices when one wants to access the array part of tables.
It makes perfect sense to add arrays as a userdata type. For these, there are benefits of 0-indexing, as seen in https://github.com/neomantra/lds - although mixing 0-indexed
[1]: https://www.cs.utexas.edu/users/EWD/transcriptions/EWD08xx/E...