Hacker News new | ask | show | jobs
by krylon 1457 days ago
> People don't like Lua

Who doesn't like Lua? That is right up there next to disliking kittens and puppies...

2 comments

Arrays start at 1?
Just like in math, and Lua doesn't do manual memory management so aligning stuff with memory addresses is not needed.

They're both valid options and it's just about preference.

> Just like in math

I might be wrong, but I think math favors different starting indices based on the subject matter. I've seen Analysis textbooks favor 0 as the starting index. I don't think there's a clear argument for cultural transference from math.

I'm opposed to starting index from 1 because I think departure from very mainstream programming tradition should have a strong reason beyond preference, even if the de facto tradition appears equally capricious.

There are good reasons for zero-based indexing outside of pointer arithmetics: https://www.cs.utexas.edu/users/EWD/transcriptions/EWD08xx/E...
It's a well-known argument. It's also widely recognized as highly subjective, starting with the notion that upper bound must be exclusive.
Indexing starts at 1 in math mostly because in history, people were afraid of 0, and it's hard to change conventions.
Debatable. It makes sense to say "the first element", regardless of mathematical connotations. We've had this kind of expression in almost every language across the world long before we invented multiplication.

Saying the "the zeroth element" is just... weird and slightly nonsensical.

Yes, because language developed at a time where people didn't know about zero.
Zero still would most likely wooldn't make sense. Zero is nothing, it can't be anything. Even ordinally.

1 is something and it fits very well for the first position... outside of programming :-)

I agree that is very weird at first. But after building a toy project including about 5,000 lines of Lua, I can say I got used to it fairly quickly. Most of the time, I was accessing arrays via iterators anyway, so I had to deal with indices very rarely.

Aesthetically, it is repulsive, but when actually writing code in Lua, it was not much of a problem. I felt much stronger about "do"/"then" and "end" versus curly braces for delimiting blocks.

Array index starts at 1

~= instead of !=

# instead of len()

Default declaration to global

-- for comments

Dereferencing something that doesn't exist returns nil