From: Robert Klemme Date: 2011-03-08T04:45:30+09:00 Subject: Re: Ruby - Missed some core computer science world ? On 07.03.2011 18:22, Adam Prescott wrote: > On Mon, Mar 7, 2011 at 4:58 PM, Robert Klemmewrote: > >> 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. Well, that could be. Then "worrying about data structures and algorithms" was probably intended to mean "implementing algorithms" - for me "worrying" includes thinking about which library algorithm to pick for a particular problem (even if it is a library of a procedural language). For that you need to know basic properties of algorithms and complexity theory. But this is not an argument specific to Ruby. Actually, all object oriented languages come with data and algorithms nicely packaged together - in a class. Even for non OO languages there are libraries which contain data structures and algorithms. It's just that in OO languages the concept of "class" is more closely related to "abstract data type" than in non OO languages. But, as I said, this is in no way particular to Ruby as a language. Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/