lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]



This thread revisited once again the question of whether
it is better to index an array starting at 0, or starting at 1:

"(Dijkstra said) everyone knows you should start counting at zero"
"Counting from zero labels one as a geek"
"User base happier starting at 1"
"Lua is NOT an inherently a 1-based language"
"That relies on pedantry: the string library IS inherently 1-based"
"Do you think that wart can be fixed?"
"Please let's not start this religious war"

I have a modest proposal, why not split the difference, and
start array indices with 1/2?

> A = {}

> for i = 1,100 do
>>  A[i - 1/2] = i
>> end

>  print ( A[1/2] )
1
> print ( A[3/2] )
2

Works fine in lua, everyone can be happy!
(What's a slight performance penalty in the interests of world peace?)

rob