Ask HN: Can Lua be remade to use 0-based numbering?

Solvency | 14 points

> 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.

jstx1 | a year ago

Outside of "programming muscle memory" (for lack of a better phrase) maybe interfering with your thought process when you're working through some random algorithms, what about 1-based indexing causes problems for people?

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.

logicalmonster | a year ago

You can change the offset in the Lua C source. It’s gonna break every single table you reference, but you can use your 0 based indexing in your scripts. Why though? I’ve used Lua for over 10 years and never had an issue with the 1 based index (I mostly use 0 based in c like languages.) I’ve never worked with anyone that cared about the 1 based indexing beyond their initial introduction to the language.

jbluepolarbear | a year ago

So in Lua the "first" element has an index of 1. There's absolutely nothing wrong with this. And most people who haven't already been exposed to C and related languages would find this perfectly natural. Because it's an index number, not an offset.

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.

rleigh | 10 months ago

Of course this is "fixable", Lua is just software.

There 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.

constantcrying | a year ago

> Lua seems like such a fun, simple, efficient language... but even on HN, people hate on it almost to the point of an absurd meme simply because its 1-based indexes.

> 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...

oweiler | a year ago

Forking, maintaining, marketing and generally all the community aspects of dealing with such a small change is not worth the effort.

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.

orbz | a year ago

And break every library there is, just for a minor inconvenience?

Damn, wait till you work with... Well, just about any language.

aspyct | a year ago

This obsessive horror with Lua's base-1 array numbering somehow overlooks the far more upsetting fact that `0` and `''` are both truthy in Lua.

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.

1attice | a year ago

Why not try it and report back?

sesuximo | a year ago

Why would you invest do much effort into making a fork which would completely, absolutely not compatible with the original language?

golergka | a year ago

If you every decide to create a scripting language, remember - it must look like C. 0-based indexing, syntax, everything. Gods forbid if you write lisp interpreter! Basically, every derivation from C will be treated as heresy and will cause countless complaints from people who never wrote a line of code in your language. /s

Seriously now: it can be done, but would be a massive waste of time.

TeddyDD | a year ago