# Ruby - Missed some core computer science world?

**URL:** <https://www.ruby-forum.com/t/ruby-missed-some-core-computer-science-world/204136>\
**Category:** Ruby\
**Created:** [March 6, 2011, 10:05am UTC](https://www.ruby-forum.com/t/ruby-missed-some-core-computer-science-world/204136 "2011-03-06T10:05:45Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![dubstep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cdc98d/32.png) [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Post date:** [March 6, 2011, 10:05am UTC](https://www.ruby-forum.com/t/ruby-missed-some-core-computer-science-world/204136/1 "2011-03-06T10:05:45Z")

</div>

I am doing ruby programming and been developing rails3 apps for some  
time now (4-5 months). I am just wondering, if the ruby world is sooo  
immersed in its beautiness and is not doing much to embrace cleverness  
in ruby world.

I mean, the whole world of datastructures and algorithms, seems to have  
much lower importance on a ruby programmer’s mind. Is it so?

I am just enjoying ruby programming for the past few months, but I feel  
that I’ve missed a lot of internal stuff in C, while was doing C  
programming. Like, datastructures like trees, linked lists, etc., and  
algorithms in C.

Also, I don’t see much “good” books on datastructures and algorithms in  
ruby or Have I missed to notice them in the market. Can you please point  
me to good datasturctures and algorithms learning book using ruby.

---

<div class="post-metadata">

**Author:** ![luckydev](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/eb8c5e/32.png) [@luckydev](https://www.ruby-forum.com/u/luckydev)\
**Post date:** [March 6, 2011, 11:34am UTC](https://www.ruby-forum.com/t/ruby-missed-some-core-computer-science-world/204136/2 "2011-03-06T11:34:42Z")

</div>

Modern computers can have 100 cores and a zillion bytes of memory. There  
is a lot less emphasis on how clever your program is. Who cares how your  
hash is stored? All you want is the most convenient code, fastest to  
build, easiest to maintain.

I can’t imagine why any but the tiniest number of Rails users would ever  
need a linked list.

---

<div class="post-metadata">

**Author:** ![luckydev](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/eb8c5e/32.png) [@luckydev](https://www.ruby-forum.com/u/luckydev)\
**Post date:** [March 6, 2011, 11:52am UTC](https://www.ruby-forum.com/t/ruby-missed-some-core-computer-science-world/204136/3 "2011-03-06T11:52:03Z")

</div>

On Mar 6, 2011, at 10:05 AM, Lucky D. wrote:

> I mean, the whole world of datastructures and algorithms, seems to have  
> much lower importance on a ruby programmer’s mind. Is it so?

There was a GSOC called “algorithms” some time ago. Besides algorithms  
it  
has datastructures like heap, rb\_tree\_map or trie.  
I think the head of this project is now in a gem called  
grosser-algorithms.

All the best, Sandor Szcs

---

<div class="post-metadata">

**Author:** ![luckydev](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/eb8c5e/32.png) [@luckydev](https://www.ruby-forum.com/u/luckydev)\
**Post date:** [March 6, 2011, 1:23pm UTC](https://www.ruby-forum.com/t/ruby-missed-some-core-computer-science-world/204136/4 "2011-03-06T13:23:08Z")

</div>

We can always say maintenance is more good than any other attribute. But  
the scale in which we solve problems, will always be limited if we don’t  
give importance to algorithms and the like concepts, in Ruby.

---

<div class="post-metadata">

**Author:** ![luckydev](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/eb8c5e/32.png) [@luckydev](https://www.ruby-forum.com/u/luckydev)\
**Post date:** [March 6, 2011, 1:11pm UTC](https://www.ruby-forum.com/t/ruby-missed-some-core-computer-science-world/204136/5 "2011-03-06T13:11:04Z")

</div>

I agree, in the Rails/Ruby community there is much more emphasis on  
beautiful code, testing, and maintainability.

---

<div class="post-metadata">

**Author:** ![luckydev](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/eb8c5e/32.png) [@luckydev](https://www.ruby-forum.com/u/luckydev)\
**Post date:** [March 6, 2011, 1:29pm UTC](https://www.ruby-forum.com/t/ruby-missed-some-core-computer-science-world/204136/6 "2011-03-06T13:29:17Z")

</div>

On Sun, Mar 6, 2011 at 10:05 AM, Lucky D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> I mean, the whole world of datastructures and algorithms, seems to have  
> much lower importance on a ruby programmer’s mind. Is it so?

Algorithms are algorithms, datastructures are datastructures. They  
exist independent of the programming language used (now, if the  
programming language of choice is up to the task is a different  
matter, and not easy to answer).

–  
Phillip G.

Though the folk I have met,  
(Ah, how soon!) they forget  
When I’ve moved on to some other place,  
There may be one or two,  
When I’ve played and passed through,  
Who’ll remember my song or my face.

---

<div class="post-metadata">

**Author:** ![luckydev](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/eb8c5e/32.png) [@luckydev](https://www.ruby-forum.com/u/luckydev)\
**Post date:** [March 6, 2011, 2:40pm UTC](https://www.ruby-forum.com/t/ruby-missed-some-core-computer-science-world/204136/7 "2011-03-06T14:40:07Z")

</div>

Lucky D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) writes:

> Also, I don’t see much “good” books on datastructures and algorithms in  
> ruby or Have I missed to notice them in the market. Can you please point  
> me to good datasturctures and algorithms learning book using ruby.

[http://cleveralgorithms.com](http://cleveralgorithms.com) - book on AI algorithms in ruby (free).

---

<div class="post-metadata">

**Author:** ![luckydev](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/eb8c5e/32.png) [@luckydev](https://www.ruby-forum.com/u/luckydev)\
**Post date:** [March 6, 2011, 2:55pm UTC](https://www.ruby-forum.com/t/ruby-missed-some-core-computer-science-world/204136/8 "2011-03-06T14:55:11Z")

</div>

Wow, that is really awesome. Thanks for sharing!

---

<div class="post-metadata">

**Author:** ![luckydev](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/eb8c5e/32.png) [@luckydev](https://www.ruby-forum.com/u/luckydev)\
**Post date:** [March 6, 2011, 4:48pm UTC](https://www.ruby-forum.com/t/ruby-missed-some-core-computer-science-world/204136/9 "2011-03-06T16:48:38Z")

</div>

Hamster is a good place to look for interesting data structures in Ruby:

> **[GitHub - hamstergem/hamster: Efficient, Immutable, Thread-Safe Collection...](https://github.com/hamstergem/hamster)**
>
> Efficient, Immutable, Thread-Safe Collection classes for Ruby - GitHub - hamstergem/hamster: Efficient, Immutable, Thread-Safe Collection classes for Ruby

---

<div class="post-metadata">

**Author:** ![luckydev](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/eb8c5e/32.png) [@luckydev](https://www.ruby-forum.com/u/luckydev)\
**Post date:** [March 7, 2011, 3:28pm UTC](https://www.ruby-forum.com/t/ruby-missed-some-core-computer-science-world/204136/10 "2011-03-07T15:28:48Z")

</div>

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?

There are of course still data structures and algorithms -rather like  
the AI book mentioned above - but what people used to talk about in data  
structures and algorithms were much more prosaic things which I suggest  
are not of the same interest nowadays.

When someone says “Why aren’t there more things about Ruby array  
searches etc?” I think there is a case for saying we treat these more as  
implementation details nowadays and typically only investigate the  
details if a performance issue crops up, so look for a higher level of  
abstraction when you move to Ruby.

---

<div class="post-metadata">

**Author:** ![luckydev](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/eb8c5e/32.png) [@luckydev](https://www.ruby-forum.com/u/luckydev)\
**Post date:** [March 7, 2011, 1:41pm UTC](https://www.ruby-forum.com/t/ruby-missed-some-core-computer-science-world/204136/11 "2011-03-07T13:41:32Z")

</div>

On Sun, Mar 6, 2011 at 10:05 AM, Lucky D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> I am just wondering, if the ruby world is sooo  
> immersed in its beautiness and is not doing much to embrace cleverness  
> in ruby world.
> 
> I mean, the whole world of datastructures and algorithms, seems to have  
> much lower importance on a ruby programmer’s mind. Is it so?

Certainly not for me but it may be the case for the community on  
average.

> Also, I don’t see much “good” books on datastructures and algorithms in  
> ruby or Have I missed to notice them in the market. Can you please point  
> me to good datasturctures and algorithms learning book using ruby.

Basically _any_ good book on data structures and algorithms will do -  
regardless of programming language used for examples. Transferring  
examples from one language to another is usually easy to do. I never  
grokked why Sedgewick wrote his algorithms books for all sorts of  
programming languages. Note, I am not saying they are bad - actually  
I believe they are pretty good. But I think he overdid it in terms of  
programming languages.

With regard to lack of data structures, if you need a tree it can be as  
easy as

TreeNode = Struct.new :data, :left, :right, :parent do  
include Enumerable

def each(&b)  
left and left.each(&b)  
b[data]  
right and right.each(&b)  
self  
end  
end

But of course it depends on the use case how your tree will really  
look like. I don’t think you’ll gain much by including a generic tree  
in the standard library because it is so easy to implement and you  
need specific code for every real tree anyway.

Kind regards

robert

---

<div class="post-metadata">

**Author:** ![luckydev](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/eb8c5e/32.png) [@luckydev](https://www.ruby-forum.com/u/luckydev)\
**Post date:** [March 7, 2011, 6:26pm UTC](https://www.ruby-forum.com/t/ruby-missed-some-core-computer-science-world/204136/12 "2011-03-07T18:26:30Z")

</div>

On Mon, Mar 7, 2011 at 4:58 PM, Robert K.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)wrote:

> 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.

---

<div class="post-metadata">

**Author:** ![luckydev](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/eb8c5e/32.png) [@luckydev](https://www.ruby-forum.com/u/luckydev)\
**Post date:** [March 7, 2011, 6:40pm UTC](https://www.ruby-forum.com/t/ruby-missed-some-core-computer-science-world/204136/13 "2011-03-07T18:40:58Z")

</div>

On Mon, Mar 7, 2011 at 3:28 PM, Mike S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
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?

How so?

I can define nodes in a tree as a class, and have the actual nodes  
lying around as objects. It can make life easier, though, since I can  
interrogate the node like an object, resulting in better consistency  
(within OO languages, anyway).

> There are of course still data structures and algorithms -rather like  
> the AI book mentioned above - but what people used to talk about in data  
> structures and algorithms were much more prosaic things which I suggest  
> are not of the same interest nowadays.

That could be because search, sorting, trees, etc. are mostly solved  
problems nowadays. Science marching on, and all that.

Besides: Why should I write my own sorting implementation, when I can  
use one that is in general use by hundreds, thousands of people, and  
take advantage of “many eyes make all bugs shallow”, as Linus says? It  
frees me from dealing with issues in my homegrown implementation, so  
that I can solve ‘actual’ problems.

–  
Phillip G.

Though the folk I have met,  
(Ah, how soon!) they forget  
When I’ve moved on to some other place,  
There may be one or two,  
When I’ve played and passed through,  
Who’ll remember my song or my face.

---

<div class="post-metadata">

**Author:** ![luckydev](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/eb8c5e/32.png) [@luckydev](https://www.ruby-forum.com/u/luckydev)\
**Post date:** [March 7, 2011, 5:58pm UTC](https://www.ruby-forum.com/t/ruby-missed-some-core-computer-science-world/204136/14 "2011-03-07T17:58:53Z")

</div>

On Mon, Mar 7, 2011 at 3:28 PM, Mike S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
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.

> There are of course still data structures and algorithms -rather like  
> the AI book mentioned above - but what people used to talk about in data  
> structures and algorithms were much more prosaic things which I suggest  
> are not of the same interest nowadays.

This could be true (less interest in DS&A) but I really regret it.  
Because this is one cause for bad software - I believe too many people  
writing code are unaware of complexity theory, graph theory etc. and  
pick inefficient data structures or algorithms (or both).

> When someone says “Why aren’t there more things about Ruby array  
> searches etc?” I think there is a case for saying we treat these more as  
> implementation details nowadays and typically only investigate the  
> details if a performance issue crops up, so look for a higher level of  
> abstraction when you move to Ruby.

I’m not sure. It may also well be that the type of software written  
in Ruby isn’t just that demanding with regard to complexity of  
calculations. When did we last discuss the most efficient algorithm  
to solve a graph connectivity problem here?

So, finally it seems the original statement (“[…] the whole world of  
datastructures and algorithms, seems to have  
much lower importance on a ruby programmer’s mind.”) very well could  
be true - but the question remains: why is it so? And: what do we  
learn from this? Does the overall importance of DS&A diminish? Or is  
this a specific development in the Ruby community? etc.

Interesting discussion nevertheless.

Cheers

robert

---

<div class="post-metadata">

**Author:** ![luckydev](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/eb8c5e/32.png) [@luckydev](https://www.ruby-forum.com/u/luckydev)\
**Post date:** [March 7, 2011, 8:46pm UTC](https://www.ruby-forum.com/t/ruby-missed-some-core-computer-science-world/204136/15 "2011-03-07T20:46:00Z")

</div>

On 07.03.2011 18:22, Adam P. wrote:

> > frequent lookup to do I choose a Hash over an Array even though I can  
> > 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

---

<div class="post-metadata">

**Author:** ![luckydev](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/eb8c5e/32.png) [@luckydev](https://www.ruby-forum.com/u/luckydev)\
**Post date:** [March 7, 2011, 10:08pm UTC](https://www.ruby-forum.com/t/ruby-missed-some-core-computer-science-world/204136/16 "2011-03-07T22:08:08Z")

</div>

On Sun, Mar 6, 2011 at 2:05 AM, Lucky D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> I mean, the whole world of datastructures and algorithms, seems to have  
> much lower importance on a ruby programmer’s mind. Is it so?

Not at all. I think Rubyists are some of the foremost users of Redis, a  
“DSL  
for data structures” implemented in the form of a network server. As far  
as  
algorithms go, some of the neatest implementations of various algorithms  
I’ve seen have been in Ruby.

One thing you can say that is true is from a professional standpoint,  
most  
Rubyists don’t need to worry too much about data structures and  
algorithms  
in their day job because the various frameworks have made the majority  
of  
the work straightforward so Rubyists can focus on writing correct  
software  
rather than spending their time reimplementing a given data structure or  
algorithm umpteen million times. Where a C programmer may find himself  
writing new linked lists or new hashes on a day to day basis, that’s not  
really a concern that will generally worry a Rubyist.

Rubyists only bust out their own implementations of a various algorithm  
when  
the problem is sufficiently novel to warrant it and there aren’t any  
libraries already available.
