Hacker News new | ask | show | jobs
by herrosheep 2751 days ago
Forth is also quite amazing. I really enjoy both.
2 comments

Lua always seemed somehow "right" to me (despite its numerous flaws, including one-based indexing), just like s-expressions somehow are just the right format for many kinds of data. You look at it and "just know". You understand it, the computer understands it effortlessly, and if you remove any element it stops making sense.

One thing both of these have in common is that they are slightly different from mainstream ideas (e.g. C, Python, JSON, XML). Not so different it becomes alien, but different enough to make you approach it with a different state of mind.

I'm not a Lua user, so I thought I'd ask why one-based indexing is a flaw. As long as it's consistent, does it really matter?

As someone who is forced to use VBA, it sounds like Lua could be worse

I have spent limited time with Lua - mostly just fiddling with pico-8. My experience has been that it's fairly easy to get used to, but occasionally annoying. For example, it doesn't interact nicely with modular arithmetic the way 0-based indexing does.
If you store a 2d array in a 1d one, it's natural to try/use x+200*y or such. With 0-based indexing it just works. With 1-based indexing, it's more complicated. If you do any modulus-based array access, 1-based indexing makes it more complicated. Basically, a world with 0-based indexing results in simpler math than a world with 1-based indexing, making it the better choice.
Because Lua is often used as an extension language of C++ which has 0-based indexing: it's really painful for programmers to switch from one indexing to another.
If x is some object then x[k] is intuitively some object at distance "k" from the beginning of x.

So the object right at the beginning is x[0].

I tend to consider one-based indexing Lua's only flaw, in fact. In particular for the LuaJIT dialect, since I'm less satisfied with the new paradigm for environments.
They have a lot in common, and there's no reason you can't have a bit of both at the same time:

https://gitlab.com/sifoo/snigl