[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: 1-based indexing in Lua
- From: Coda Highland <chighland@...>
- Date: Thu, 29 Mar 2018 15:12:33 -0500
On Thu, Mar 29, 2018 at 2:11 PM, Dong Feng <firstname.lastname@example.org> wrote:
>> The argument isn't that it's absolutely bad for a language to have
>> 1-based indexing.
>> The argument is that it's bad to MIX 1-based and 0-based indexing in
>> the same system, and unfortunately for Lua's design as an embeddable
>> and extendable language, that's exactly the case here. The vast
>> majority of applications that will embed Lua will use 0-based indexing
>> internally, and a similar majority of libraries that one might wish to
>> bind to Lua will also use 0-based indexing.
> I think people are customized to the 0-based indexing in the context of C.
> But that's all about it, just a custom, and one should be restricted within
> the C context (because everything is more or less an offset).
> A programmer could more easily fall into more serious trap if he/she mix the
> mindset of offset and index (e.g. using continuous block with using
> non-continuous data structure). I think Lua's approach, though not solving
> all problems (and has its own pitfall), is not by nature inferior to a
> universal 0-base indexing system. We would explore auxiliary pattern such as
> always naming parameter properly as "index" or "offset".
Yes, that's... exactly what I said: It isn't by nature inferior, but
mixing up the mindsets is the real risk, and Lua's nature as an
embeddable/extensible language puts it in a position where you might
have to be exposed to both at once.