Matt Todd wrote: > This is a very interesting hack, though I don't really think it is a > good one to implement. Maybe as an extension (which would be really > cool, though I have a hard time seeing that working), but not as > default. I tentatively disagree... > I believe that I've heard that one of the reasons why it's not sorted > any particular way is due to a performance increase in the randomness > of it. I can't verify that, as that's outside of my expertise, but I > don't wish to have Ruby any slower. Not really, as I understand it. The reason the order gets scrambled is because it's implemented internally as a "true" hash (as in "hashing function"). I believe that Nobu once made a patch like this and (as I recall) reported no significant speed hit. (Some small memory hit, of course.) Nobu? What can you tell us? > But, really, my biggest reasoning is that order doesn't matter to a > dictionary/hash. What matters, above all else, is that you have a > collection of keys that refer to their associated values. Sure, some > kind of ordering would be good for some occasions, but, honestly, I > don't need it often, if ever. When I need some kind of ordered set, I > use an Array. I ask myself: if I really need this ordered, am I really > working with a hash/dictionary, or am I working with an array? You have a good point. But the thing is, the Hash class has *two* things I like (two things that make me like hashes). It consists of *pairs* of items (associations), not just single items. (Of course, you could view an array as associating integers with objects.) Also the keys don't have to be integers. And thirdly, it has a convenient literal notation (as arrays do also). > Lastly, though I can't see using it (any time soon, at least), I do > understand that it has valid uses. I don't see Rick's example syntax > to be too far-fetched an alternative to simply using a hash literal > (which I don't use too often, anyways), as uncomfortable as it may be. > But, then again, it's an Array, isn't it? Hmm. But, really, I'm sure > you could figure something out that works well. > > Just don't mess with my hash... ;D I once had the idea of a separate OrderedHash class with a literal notation that Ruby would recognize: unord = {a=>1, b=>2, c=>3} ord = [a=>1, b=>2, c=>3] It even looks array-like. Trouble is, Ruby already recognizes such a notation as being an array with a single element which is a hash. I am more likely to ask for changes outside the parser than inside it. Hal