On Nov 23, 2011, at 13:27, David Herman wrote:

> An additional point about consistency: many scripting languages talk about 
> the "length" of a table data structure because they actually expose the 
> representation of a table as an array or list.

I dispute your examples, as follows:

> IIRC Perl/PHP associative arrays,

In Perl, _hashes_ are different builtin objects from _arrays_; they merely have 
useful conversion behavior when used in _list context_ (which is a 
call-semantics issue unrelated to data structures). The way to get the number 
of elements is to call 'keys %myhash' in scalar context. 'length %myhash' will 
do something useless. I'm not familiar with PHP.

> Python dicts,

Again, different builtin objects. If they have any array nature, it is not 
exposed to the programmer; myDict[key] gets you a lookup by hash key, not array 
indexing.

> Lisp alists,

An alist in Lisp is not a distinctly typed data structure at all; it is only 
and entirely a particular application of linked lists (which are an application 
of cons cells (pairs/tuples)) for which there are utility functions in the 
standard library. A (Common) Lisp programmer looking for the size of an alist 
would indeed (length my-alist), but if they had a hash table it would be 
(hash-table-count my-ht). (In CL, the length function applies to all 
_sequences_, but a hash table is not a sequence; there are no functions generic 
over all kinds of collections.)

> and Ruby hashes are all transparently built from arrays or lists. But Map and 
> Set aren't arrays, they're their own data structure. So IMO it makes sense to 
> name their methods on their on terms, not on the terms of a different data 
> structure.


(For what it's worth, I agree with the previous suggestion to make .length used 
only for things which have [0], [1], [2], …; and that if it is instead a 
collection with .get() and .put()/.set() or similar then .size() or .count() 
makes sense.)

-- 
Kevin Reid                                  <http://switchb.org/kpreid/>

_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to