lua-users home
lua-l archive

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



> Am 29.03.2018 um 19:01 schrieb Coda Highland <chighland@gmail.com>:
> 
> On Thu, Mar 29, 2018 at 10:30 AM, Dong Feng <middle.fengdong@gmail.com> wrote:
>> 
>> 
>> On Thu, 29 Mar 2018 at 01:52 Axel Kittenberger <axkibe@gmail.com> wrote:
>>> 
>>>> 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.
>>> 
>> 
>> It's not if there is proper justification. 0-based indexing should be an
>> "offset". It's justified in C because C array indexing is always an
>> "offset". You can write:
>> 
>> int a[3];
>> 1[a] = 5;
>> *(a+2) = 6;
>> 
>> Not the case for all languages' arrays.
> 
> 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.

If you embed Lua in any hosting program, you will have to carefully provide Luaisms anyways (iterators, strings as options etc.).  So index basing is one such thing.  An come on, adding or subtracting 1 really isn’t that hard, right?

> 
> While it is of course possible to translate between the two at the API
> level so that each language involved can operate using their own
> preferred style, programmers that are working in both the host's code
> and Lua code, or who are using the same library both directly and
> bound to Lua, will have to mentally switch between the two indexing
> styles, which increases the likelihood of human error.

I disagree strongly.  This is exactly my day job, to dig in C and Lua code and make sure they properly interact.  It’s really easy to get this right.  And yes, I even speak more languages than my mother tongue and I can switch on the spot…

> 
> Obviously, it's stuff that's usually going to shake out during testing
> and debugging. But it's still a level of overhead that wouldn't be
> there if host language and embedded language were in agreement.

Two languages can never be in „agreement“ because they are, well, different languages.

> 
> On the other hand, it would be a BIGGER source of errors to CHANGE the
> status quo after the ecosystem has been established. This is the
> reason that I have never argued that Lua should change -- it's a speed
> bump, but only a minor one, and one that any competent developer will
> be able to manage with experience; the alternative is far worse.

Changing this would indeed be a very bad idea ;)

> 
> /s/ Adam
>