lua-users home
lua-l archive

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


On Tue, Jun 28, 2016 at 6:17 PM, Andrew Starks <andrew@starksfam.org> wrote:
> First, `__len` is about sequences and this isn't a sequence. This
> extra metatable is more about making `#(table.pack(...))` work as you
> would *hope* (maybe naively expect, but you'd be wrong) and that is a
> conspicuous amount of fanciness in such an austere language.

A 'conspicuous amount of fanciness' is totally not the Lua spirit ;)

I suspect we're starting to spin around an old familiar whirlpool by
now.  It's hard for me to judge, since I like tables and know how to
keep them being sequences.  But the 'horror of holes' definitely comes
up with questions from newcomers. It's natural to expect that a table
knows how _big_ it is.  The special restrictions of # would then
appear confusing [0]

[0] In a similar vein, a colleague got burned by std::list.size() in
C++ - he assumed it was O(1) but it was O(n)! [1]
[1] fixed since C++11, thank the Goddess...