From: Alex Young Date: 2006-07-26T05:12:43+09:00 Subject: Re: Hash order bug? Kero wrote: > [snip] >>>>> What's happening? all my code is behaving wrong because of that. >>>> Hashes are unordered. If you need an ordered collection, you'll need >>>> to use an array. >>> Oh my god, i didn't know it, sorry. Is that a missing feature? >> Debate rages on this point :-) It's mostly a speed issue, I think. >> At least my memory is that Matz's latest statement was to the effect >> that he would do it if it could be done efficiently. >> >> The question came up during a lunch here at OSCON (with me, Jim >> Weirich, Pat Eyler, and a fellow named Nicolas whose last name I'm >> afraid I don't remember) as to whether making hashes ordered in a >> future Ruby would break any existing code. I think the answer is no, >> which is kind of interesting considering what a major change it would >> be. It's a case where the feature would be purely additive. > > I guess there won't be many ppl using algorithms that use the *un*sorted > aspect of a Hash. It's not that it's unordered, it's that it's anordered. The concept doesn't apply. It's a bucket, not a queue. There are many, many applications that don't care about entry order. >Using Kernel#rand instead of Object#hash seems > better. printing a few hash-values suggest they're not that random anyway... The order is unpredictable and implementation dependent. -- Alex