|
|
|
|
|
by mfost
1362 days ago
|
|
Saying it's strictly better is exaggerated. The benefits of 0 indexing are well known and mostly revolve around the fact you tend to have far less fiddling with -1 and +1 as you write code. 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. |
|
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...