-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1


On Jan 24, 2008, at 10:02 AM, 7stud -- wrote:

> Michael Schmarck wrote:
>> yermej <yermej / gmail.com> wrote:
>>
>>> I'll offer up an inject version (mostly for novelty's sake):
>>> timing_given.each {|k, v| timing_given[k] = v.inject(Hash.new {|h,  
>>> k|
>>> h[k] = []}) {|acc, h| h.each {|k, v| acc[k] << v}; acc}}
>>
>> Geez - did you use to code perl code? Because Perl code tends to
>> be as unreadable and compact as yours :)
>>
>> It works good, but I guess I've got some reading to do, to actually
>> understand why it's working ;->
>>
>
> Don't bother.  inject() is such an inefficient function it should  
> never
> be used in ruby code.


No, it's too slow only if you have profiled a specific application and  
the profiling software pegs it as being the culprit. Premature  
optimization and all that.  If it's only going over a small data set,  
it probably doesn't matter.   If it *does* matter, then there's  
probably a bigger algorithm problem.  In the meantime, it presents a  
syntactic sugar for some people.

But if that code was sugar, I think there's some vinegar in it ...   
inject probably isn't the right answer in terms of maintainability in  
this case.  After all, yermej said it was for novelty's sake. :)


David Morton
Maia Mailguard http://www.maiamailguard.com
mortonda / dgrmm.net



-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (Darwin)

iD8DBQFHmOq1Uy30ODPkzl0RAiZYAKC+zC1rJxiWCqbAZHec0mRxMJivowCgimmH
+v2xp6hWUwXhRAnxfd6OzPw=
=cTQQ
-----END PGP SIGNATURE-----