From: mathew
Date: 2011-01-22T02:43:44+09:00
Subject: [ruby-core:34758] Re: Hash iteration contract (was Re: Let's begin a talk for "1.8.8" -- How's needed for surviving 1.8?)
On Thu, Jan 20, 2011 at 09:53, Zeno Davatz wrote:
> We are just working on our Ruby 1.9 application and we just found another
> consistency problem in Ruby 1.9. The way Hashes are iterated in Ruby 1.9.1
> is different from the way Hashes are iterated in Ruby-1.9.2.
I brought this up in December:
I wrote:
> Is it really a good idea to specify the order in which keys are
> returned? That could have major implications later on if someone wants
> to rewrite Hash to increase performance.
I still think it's a bad idea to guarantee any particular ordering
when iterating hashes.
For example, Java's HashMap class says:
> This class makes no guarantees as to the order of the map; in particular, it does
> not guarantee that the order will remain constant over time.
My feeling is that if people want to iterate through hash keys or hash
values in a particular order, they should sort them explicitly, or use
a more special purpose SortedHash class. The rest of the time we
should be able to use a Hash class that offers no key or value
ordering guarantees, but is as fast as possible as a result.
mathew
--