If you search the forums, this fundamental issue is mentioned thousands of times over years and years.
Which leads me to a naive question: Lua is open sourced. Why hasn't anyone in the world just forked the language to be 0-based? Is it not as simple as it sounds? I don't know what goes into designing and compiling a programming language, so it seems like such a trivial fix for what appears to be the #1 issue for every person out there allergic to Lua.
It isn't.
Having worked with languages that have both 0- and 1-based indexing (sometimes at the same time), this is at the bottom of my concerns when evaluating a language. It's the "tabs vs spaces" of programming language comparison. Right there with "does it have semicolons" and "is whitespace significant". None of these things are important.
That's why it's so low on the list of importance when considering language features; it doesn't fundamentally change what the language does or how it's organized (perhaps beyond some contrived examples) and instead only affects what the code looks like.
I've never gone too far deep into 1-based languages, but it seems like it would avoid a lot of off-by-one errors once you get used to it.
It's only in C and C++ where the memory location of an element can be expressed as base+offset that we end up using the offset rather than an index. That has clear logic behind it and absent optimising compilers it may be marginally more efficient, but it does not make for the most user-friendly interface--it does break the expectations of most other people.
If I'm working on providing a Lua library interface for non-developers, they will find the default Lua behaviour far more natural than were I to force zero-based indexing upon them.
I’m beginning to wonder whether a language that doesn’t have indexes at all would be viable.
Swift abandoned C-style for loops (https://github.com/apple/swift-evolution/blob/main/proposals...)
It still has enumerated (https://developer.apple.com/documentation/swift/sequence/enu...()), though.
That’s a special case of zip, though, and programs could use
or according to their preference.Also, slices could be created using
instead of Implementation-wise, those are identical, but conceptually, the first doesn’t use indexesThere is also nothing wrong with One based indexing. Zero based indexing exists for historical reasons and because most people are comfortable with it they feel uncomfortable with the alternative, that is easily overcome though.
As an aside, the One based indexing is the mathematical convention, which is why e.g. MATLAB consciously choose it.
>Why hasn't anyone in the world just forked the language to be 0-based?
Significant amount of effort for an extremely minor change.
> If you search the forums, this fundamental issue is mentioned thousands of times over years and years.
> Which leads me to a naive question: Lua is open sourced. Why hasn't anyone in the world just forked the language to be 0-based? Is it not as simple as it sounds? I don't know what goes into designing and compiling a programming language, so it seems like such a trivial fix for what appears to be the #1 issue for every person out there allergic to Lua.
I wonder how many of those who complain have actually used Lua? Same with all the Perl/PHP haters...
Many other languages have chosen one-based indexing for the same reasons: all of them are languages that have a high incidence of dealing with real-worrd data and relationships: In addition to Lua (a beautifully elegant language) there's FORTRAN, Julia, Tcl, Awk, Mathematica, Matlab, COBOL, Smalltalk, and quite a few others. The architects of these languages made very deliberate decisions to prefer one-based indexing.
One-based indexing makes a LOT MORE sense for most real-world work, and as noted, avoids the ubiquitous off-by-one errors that pervade the unnatural zero-based indexing.
It’s not the only big 1 indexed language (R, COBOL, Wolfram, Smalltalk, etc.), sometimes as engineers we just have to get used to idiosyncrasies between languages similarly to how bilingual people do the same with spoken language.
Damn, wait till you work with... Well, just about any language.
To be clear: I love Lua; but if you're going to have a reaction, please react to the features that are genuinely counterintuitive, rather than (if you will) counter-counterintuitive.
The merge of existence checks and boolean operations in the same operator is wrong.
Which is that, despite loving Lua, I can recognize that it features several 'improvements' which are going to cause Surprise for a lot of coders. Which is bad, following the Law of Least Surprise.
Personally, I agree with you, but I can also see why Lua initially turns a lot of people off; it took a good year of meeting it in my Neovim config before I accepted that it wasn't some horrible corruption of JavaScript. Now I tend to think of Lua as an improvement over JavaScript: spare, elegant, and almost perfect.
But I remember that first year, and I can still empathize with people in their first year of Lua.
Seriously now: it can be done, but would be a massive waste of time.