lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


If you want to start counting from zero, do so. Lua won't stop you doing that.
You may even start at -1 or whatever you like.
It's not a Lua limitation, only the functions in the table module are used to count from 1 to N (not 0 ... N-1)

Personally, I do like 1-based indexing. As far as I know, zero-based indexing came into the play when the C language was designed with the preprocessor substituting array expressions like A[2] with *(A+2).
BTW: Did you know that 2["abc"] is a valid C syntax?

Regards,

Oliver

Am 14.11.21 um 23:17 schrieb Steven Degutis:

Hello Lua community and Lua team,

 

It’s true this would be breaking, but Lua has traditionally not been afraid of breaking backwards compatibility in some important things, even in 5.x versions. Since this is a bigger jump, I’m recommending it for Lua 6.

 

I’m well aware of the benefits of 1-indexing, but at this point in the human-wide history of software, roughly 30 years after Lua came out, practically every other language uses 0-indexing, and practically every programmer must become familiar with it at some point.

 

Even when using Lua interop with other libraries, Lua-only users will have to eventually learn 0-indexing with all probability.

 

Plus, there are unique advantages to 0-indexing, e.g. offset=0 for first item, which is useful in countless situations.

 

However this request will be received, it’s not my intention to start a flame war or debate. I’ve made my case, and I have no further points to make. Thanks for reading.

 

By the way, thanks for creating and maintaining a great language. It’s especially fun to use in Pico8 and Love2d.

 

Regards,

Steven Degutis