Re:Lua, a Misunderstood Language (2021)
by tromp on Thursday September 29, 2022 @02:42PM
(#33025267)
> "what is the index of the last item?" 5
Usually, the more interesting question is:
What is the index of the next item (when extending the array)? Which is 5 in 0-based indexing.
Re:Lua, a Misunderstood Language (2021)
by shoemakersteve on Thursday September 29, 2022 @05:13PM
(#33027300)
Is it? If you're doing low-level stuff maybe, but I really haven't done much of that so I'm not even sure I know what you mean by "extending" an array (presumably has something to do with allocating contiguous memory?) and I can't actually think of any situation off the top of my head where I would ever need "the last index + 1" what with array methods existing and all.
"give me the 2nd item" --> a[2]
"how many items are in the array?" 5
"what is the index of the last item?" 5
I am used to 0-indexed and prefer consistency... yet there is an undeniable consistency to 1-indexed.
You're the person who brings back a dozen bottles of milk from the store when you see that they have eggs ;)