On Tue, Aug 15, 2000 at 11:46:04PM -0400, Stephen P. Potter wrote:
> Why is it silly?  Hashes and arrays are *conceptually* very similar (even
> if they are extremely different implementation-wise).  One of them has
> implicit key, the other has an explicit key.  They both provide some sort
> of ordered collection (plural), even if it is difficult to understand what
> the order is of hashes.  Seems to me we could eliminate arrays and just
> keep hashes.

Arrays are ordered.  Hashes are not.  Sure, you can iterate over a hash,
but add an element to one and you can change the order of everything in
it.  You are guaranteed that won't happen with an array.

Looking up a value in an array is faster than doing so with a hash.
Appending a value to an array is usually faster than adding an element
to a hash, but inserting elements into the middle of a large array will
generally be slow.

Hashes consume more space than arrays containing the same number of values.

Plenty of other differences.  Sure, most of them are connected to the
implementation and efficiency, not the abstract concept of arrayness and
hashness -- but Perl is a Practical language, and practical programmers
like to know these things.

You can change a lot of these things by twiddling with the internal
implementations, but at the end of the day "ordered set" and "mapping"
are conceptually and practically different beasts.  I don't think there
is any reason for Perl to want to toss away the distinction.

                         - Damien

Reply via email to