4 ms·
>for example indexing starting at 1 is definitely an oddity. Only to programmers raised in a C-based world. Normal people, mathematicians, and Lua start counti
by copx 14y ago
>for example indexing starting at 1 is definitely an oddity.
Only to programmers raised in a C-based world. Normal people, mathematicians, and Lua start counting at 1.
I remember when I was new to programming I was horribly annoyed by the fact that C started counting at 0 - that was so unnatural! (the BASIC I had used up until that point used 1-based indexing too)
0-based indexing is good for low-level code, for memory and screen addresses. For high level concepts starting at 1 is the natural choice.
However, I admit after many years of C/C++ I was quite irritated by everything starting at 1 by default. My brain adapted after a few days, though.
I think the Lua devs made the right choice with the 1-based indexing. Just like 0-based indexing was the right choice for C. As I said both ways are natural but in different scenarios: 0-based for low-level machine code, 1-based for high level human concepts.
- azakai 14y ago> Only to programmers raised in a C-based world. Normal people, mathematicians, and Lua start counting at 1. I mostly agree, except for mathematicians ;) , where it depends on the context. For example aleph numbers start at 0, http://en.wikipedia.org/wiki/Aleph_number http://en.wikipedia.org/wiki/Aleph_number and even the natural numbers can start at 0 or 1, http://en.wikipedia.org/wiki/Natural_number http://en.wikipedia.org/wiki/Natural_number
- SomeCallMeTim 14y agoI think the key here is that people ALWAYS complain about Lua indexing from one. Aside from that, not having a huge standard library is the second complaint. There are debates that come up all the time on the Lua list about what would be best, but I think those are really the main complaints people have. Large standard libraries would mean huge potential for security holes in this case; they've locked features down to only support things that they could make secure. And starting from 1 you can get used to. LuaJIT doesn't even REQUIRE you start from 1; it'll optimize arrays you start from zero. And even vanilla Lua will accept 0 as a table index; it just won't treat it as an array (for ipairs() or length). But if you start asking people for complaints about JavaScript, you will find people complaining about operators acting wonky, auto-type-conversion problems from hell, and even odder things like [1]. Lua is just a cleaner design. I am stuck using JavaScript when I want to work on the web, but knowing what an elegant language CAN be makes me enjoy it a lot less. And don't get me started on how ugly NodeJS is because JavaScript doesn't have coroutines... [1] https://news.ycombinator.com/item?id=3401074 https://news.ycombinator.com/item?id=3401074