lua-users home
lua-l archive

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

On Wed, Jun 24, 2009 at 12:36 PM, Luiz Henrique de
Figueiredo<> wrote:
>> Given the persistent confusion about arrays vs. tables, and the scope
>> for really nasty hard-to-find bugs if people get it wrong, it might be
>> worth considering a 'strict mode' option (by default off, of course)
>> that cause #, table.remove/insert etc to *fail* if you give them a table
>> that's not an array. By fail, I mean throw an error to cause you
>> application to stop.
> How do you propose to do that? I mean, how can the Lua core detect that a
> table is not an array without traversing it completely?

Not to mention, you can already do this yourself in Lua.  Rather than
using raw table constructors you create your own library of functions
that maintains the proper structure in the table.  With metatables
this is easily accomplished and is no more "difficult" than putting
something like this into the core.

Sure, one might argue that it would be nice to have these "features"
for raw Lua tables, but I don't really see any reason for that.  If
someone is going to be using the raw Lua tables, then I expect them to
read up on how they work.  Covering this topic in my book really
didn't take all that much time and I've yet to have someone come to me
that didn't understand it.

- Jim