lua-users home
lua-l archive

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


2018-03-29 7:48 GMT+02:00 Charles Heywood <vandor2012@gmail.com>:
> Lua is the most commonly used, though. ColdFusion also gets some nitpicks
> about it but there's so many other reasons to pick on CF.
>
>
> On Thu, Mar 29, 2018, 12:47 AM David Crayford <dcrayford@gmail.com> wrote:
>>
>> I've never understood why Lua attracts so much opprobrium for 1 based
>> indexing. I started my career working on mainframes and all the
>> languages had 1 based indexing (COBOL, PL1, Fortran, REXX).
>> It wasn't until I started using C that I had ever used a language with 0
>> based indexing which makes sense for a language where arrays decay to
>> pointers. IMO, the Lua authors got it right.

Agreed.

Moreover, it is not strictly correct to say that Lua has 1-based indexing.

Even to say that the Lua standard library and the default length
function have 1-based indexing, is only partially correct. When
working with bytes in files, the io library has 0-based indexing.

The actual range of indices in a table can be anything the user wants.
Negative indices are useful; take for example the 'arg' array. I much
prefer the Lua way, where t[-1] means t[-1], to the Python way, where
t[-1] means t[#t-1], and to the C way, where t[-1] means "let's hope
the pointer t is pointing to something that won't make the program
crash".