lua-users home
lua-l archive

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



On Jun 25, 2016, at 3:15 PM, Philipp Janda <siffiejoe@gmx.net> wrote:

Ignoring syntax and compatibility issues for a moment, what would you have
if a table had an explicit, unambiguous, first-class array length?

— No confusion over the meaning/behavior of ipairs().

What about `ipairs()` is confusing? It's just like with C strings: the first `NUL`/`nil` terminates the thing. Normal Lua tables on the other hand are like Pascal strings that only remember their capacities, not their sizes, so you have to find the (or a) terminating `nil` anyway.

It’s confusing when # does one thing and ipairs() does another. If you recall the debate over changes to ipairs() prior to Lua 5.3 (and the changes it underwent during the betas) than yes, I think it can be called confusing. Remember that as a scripting language Lua often has programmers who have far less software knowledge than a seasoned C/C++ veteran, and so the language really needs to be as consistent as possible (imho).

And you only have to look at the number of times the whole issue with sequences/#/nil comes up in this mailing list.

—Tim