From: Adam Prescott Date: 2011-03-08T02:22:32+09:00 Subject: Re: Ruby - Missed some core computer science world ? --20cf302d49a0cd856f049de7b962 Content-Type: text/plain; charset=UTF-8 On Mon, Mar 7, 2011 at 4:58 PM, Robert Klemme wrote: > On Mon, Mar 7, 2011 at 3:28 PM, Mike Stephens wrote: > > Robert > > > > Surely, when you elect to use objects, and you are inclined to use > > things like .each or .sort, you are making a choice to move away from > > worrying about data structures and algorithms? > > No, I don't think so. I worry about DS&A all the time. When I have a > frequent lookup to do I choose a Hash over an Array even though I can > use Array for lookups as well (unless the key is an integer in which > case an Array may work as well or better). It's true, I take > Array#sort for granted and rely on the fact that it is implemented > efficiently - much the same as when using qsort() in a C program. > I could be wrong, and I hope this makes sense, because it's not entirely clear to me, but I think the argument is that Hash and Array, in their basic use, provide interfaces for what could be any concrete implementation of an abstract associative array and an abstract list, so that the choice of Hash vs Array is less about how Hash and Array are actually implemented, which would involve a decision based on performance. I believe that's what the ".each or .sort" is in reference to, in that, for an Array, we might not care how it's implemented -- it's ordered and we can iterate over it with .each. --20cf302d49a0cd856f049de7b962--