upvote
I find that in practice the amount of +-1 is about the same for zero-based and one-based indexing. Each has situations it is better suited for. For example, iterating a list backwards is nicer with one-based indexes.
reply
I think it's inclusive indexing in general that make reverse iteration nice, not necessarily whether it's based on 1 or 0. (Namely, an ergonomic way to access the index of the last element as opposed to the length of the list. With inclusive indexing, the length is already naturally the index of the last element.)
reply
That is absolutely not the case.

Numerical loops in Lua are inclusive:

    for i=1,#t do t[i]=0 end
On the example above the i starts at 1 and goes up to (and including) the length of t.

With 0-based indexes, and that numerical loop format, it would be minus-one everywhere:

    for i=1,#t-1 do ...
reply
I don't see a contradiction? I specifically pointed out inclusive indexing as part of my complaint.

The funny thing is, you could say the end index is zero-indexed and exclusive and that would result in the same behavior as one-indexed and inclusive. It wouldn't make sense to make it zero-indexed and inclusive, because the inclusivity only exists in the first place to account for the one-indexing. That would be an incomplete and nonsensical conversion.

reply
These days all you gotta do is ask your local LLM to write you a Lua with 0-based indexing. Sure beats complaining about 1-based indexing on HN until the end of time.
reply
Oh right. When I signed up for HN with the goal of complaining about 1-based indexing until the end of time, I hadn't considered that LLMs didn't exist yet. Thanks for updating my knowledge date!

Jokes aside, I did start to do a conversion like this manually some years ago, but it wouldn't really be Lua at that point. I just got bored because I knew it wouldn't really have value to anybody.

reply