develooper Front page | perl.perl5.porters | Postings from July 2013

Re: Should we make hashes return keys in FIFO order?

Thread Previous | Thread Next
From:
Zefram
Date:
July 26, 2013 13:21
Subject:
Re: Should we make hashes return keys in FIFO order?
Message ID:
20130726132136.GN29255@fysh.org
demerphq wrote:
>Various languages make their hashes return items inserted into them in
>first in first out order. I was wondering if we should do the same.

No, we should not.  Currently, elements in our hashes are unordered,
and logic such as data serialisers can rely on that.  If we change to
preserving order of hash elements, then we change the scope of the
data structure, and every general-purpose data serialiser needs to
start representing and preserving that order.  Anything that currently
sorts the keys of a hash for display would be incorrect, in that it's
no longer fully representing the hash content, and some of them will
change, and that'll be a hassle for anyone using the hash in the old
way who therefore wants the sorting.

Basically, an ordered associative array is a different data structure
from an unordered associative array, and Perl's hashes are the latter.
Don't foist a different data structure on people who have already
chosen one.

-zefram

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About