<thoran / thoran.com> wrote in message 
news:2d4684b07b9f965e5078fdb46754fac3 / shiny...
>I was surprised to find the following...
>
> I realise that it is a hash and that access is expected to be by key, but 
> sometimes retaining the presented order may be desired.  And anyway, why 
> reorder it at all?

    I am always surprised whenever this question comes up.  Whenever it 
does, it's obvious that the poster does not know what a hash is.

    I think what you are thinking of is a red black tree (or just a binary 
tree, in general) and not a hash...


> It doesn't seem very PoLS to have it reordered, although perhaps one 
> shouldn't be surprised that a hash is unordered?  Perhaps Matz is 
> convincing us of this statement?  Said Matz unto the flock in a loud, 
> Godly voice: "Make no assumptions about the order of hashes!"

    People invoke the PoLS way too often considering it's a claim that Matz 
has never made.
    Personally, the Principle of Least Surprise is more about consistency 
than it is about how often you're literally surprised.  Often, you're 
surprised because of your own ignorance (as in this instance), so you can 
hardly blame Ruby for that!  Ruby is very consistent and, in my opinion, 
follows the PoLS.  Whenever it doesn't, it ususally does so for a good 
(pragmatic) reason...


    Honestly, complaining that hashes aren't ordered is like complaining 
that rand() doesn't return the same number every time.  Pray tell, what 
made you think it should be ordered?  That was an honest question, by the 
way!  You know enough about programming to come here and decree that this 
is very weird yet you didn't already know what a hash is or how one works. 
Very strange...