Mailing List Archive


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [tlug] Are ordered hashes useful?



On 11 February 2011 13:09, Kenneth Burling <burlingk@example.com> wrote:

> My understanding of Hashes was that Hash keys are quite often a way of
> getting away from the need for predictable ordering.

That's one reason. Some others are:

* O(1)--i.e. constant time--access
* meaningful indexes; you often do stuff like this: my_hash.each.map
{|key, val| key =~ /foo/ ? something(val) : something_else(bar) }
* human-readable params in languages that do not natively support
named params (Python does, Ruby 1.8--and 1.9 as well, IIRC--and Perl
do not)

I'm sure I'm missing some other good uses for hashes. :)

-- 
Cheers,
Josh


Home | Main Index | Thread Index

Home Page Mailing List Linux and Japan TLUG Members Links