lua-users home
lua-l archive

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


> Present behavior:
> With a sequence: # returns valid length
> Without a sequence: # returns arbitrary integer value that is easy to mistake for a length
> 
> Suggested behavior:
> With a sequence: # returns valid length
> Without a sequence: # returns nil
> 
> Why is the suggested behavior bad?

Two possible reasons that deserve more thought:

- Performance. Every assignment to an integer key has to check whether
it is keeping/breaking a sequence. (If you add n elements to a table,
the accumulated overhead of these checks is O(n), just like any other
check for table sequenceness.) Even the majority of programs that do not
need such thing will pay for it.

- Reasoning. The proposed behavior can be as baffling as the current
one.  ("Why is this table not a sequence??") For instance, every
algorithm that manipulates a sequence (e.g., sorting methods) will have
to be carefully checked to see whether it can assign a nil temporarily
in the middle of a sequence.

-- Roberto