lua-users home
lua-l archive

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


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

Mixed 1-based and 0-based indexing is the worst possible state of affairs regarding this for a programming system.

As I replied in that survey discussion recently, where remarkably many 1-based languages are rated in the "most hated" section.
If you have to mix it is bad for one's brain and since this question likely revolved around "programming languages I have to use beside my main language" this is the result of the majority of currently popular programming languages are 0-based. Not to argue it is better by itself, but there is definitely a bandwagon effect.

On Thu, Mar 29, 2018 at 10:36 AM, Dirk Laurie <dirk.laurie@gmail.com> wrote:
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".