Hacker News new | ask | show | jobs
by pacoverdi 744 days ago
I had two encounters with Lua many years ago.

The first to write "stored procedures" in Redis (I forget the correct terminology). It allowed to improve the performance of Django endpoints by an order of magnitude.

In the second, I wrote a Wireshark plugin (also not sure of the proper term) to dissect a proprietary protocol.

I don't remember the details but this is not a programming experience I look forward to renew... (Same feeling about Perl btw)

Possibly indices starting at 1 were the most disturbing.

1 comments

Indexes do start at one. Offsets start at zero.

If you have a table of 5 apples and the middle one is rotten do you say the rotten one is the 2nd or 3rd?

That was a surprising downvote.

I was referring to this:

"it is customary in Lua to start arrays with index 1" [1]

Not being a native English speaker, I may have phrased something wrong. I find "one-based indexing" in arrays not particular intuitive, and error-prone.

Better?

[1] https://www.lua.org/pil/11.1.html

No, what you phrased is a common argument but IMO doesn't follow from natural language. The fact that C uses pointer offsets as it's "indexes" is IMO the truly counterintuitive thing.

Obviously I use 0 based indexes for most of my programming. I have not found 1 based indexing to be a serious problem since Lua is a high enough language that I'm rarely doing complex index arithmetic.

FYI I didn't downvote you.