tech-kern archive

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

Re: Lua in-kernel (lbuf library)



Marc Balmer <marc%msys.ch@localhost> writes:

> Am 15.10.13 23:01, schrieb Lourival Vieira Neto:
>
>>> Also, having to switch mentally between zero-based arrays in the kernel C
>>> code and 1-based arrays in the Lua code make my head ache.
>> 
>> It's something that doesn't bug me so much.. But, if necessary it
>> could be changed to 0-based in this userdata.
>
> In C an array index is actually an offset from the top, so 0 is the
> natural way to denote element nr. 1 in C.  In Lua, a numeric array index
> is not an offset, but the ordinal array position.  So 1 is the natural
> way to denote the first element.
>
> Strictly speaking, it's actually C that is weird:  Index n denotes array
> element n + 1...

This depends on your background. If you studied or dealt with mathematical 
logic,
set theory, or foundations of mathematics, then you start counting natural 
numbers
(ordinals) from 0. In this respect C is more logical (pun intended) than Lua.

> Following the principle of least astonishment, I would not recommend
> starting to do 0 based stuff in Lua, a Lua programmer certainly expects
> things to start at 1.

It is hard to tell what is the least astonishing here. You propose Lua
as a language embedded into C rather than separate one. I'd say that Lua
designers made wrong decision here.


-- 
BCE HA MOPE!



Home | Main Index | Thread Index | Old Index