Yesterday I cam across a Web page mentioning this book on "Data Structures and Algorithms with Object-Oriented Design Patterns in Ruby" by Bruno R. Preiss.
http://www.brpreiss.com/books/opus8/
I'd like to know if anyone has read this book with care and has an opinion about it? I spend an hour or so on it and was under the impression that the content was good but that the source code of the examples look a bit too Java-ish.
Note: The same book for JAVA and C++ was published on paper by Wiley.
Thanks for you comments.
Laurent
Laurent Julliard wrote:
[...] I'd like to know if anyone has read this book with care and has an
opinion about it? I spend an hour or so on it and was under the
impression that the content was good but that the source code of the
examples look a bit too Java-ish.
Hi Laurent,
versions of the book exist for C++, Java, C#, Python, Lua, Perl, PHP and
Ruby. The focus is clearly on the algorithms and the code is just
adapted for the given language. It's not idiomatic Ruby.
While idiomatic C++, Java and C# are roughly similar, this is not the
case when you also consider Ruby, Perl or Python.
For example, Program 2.6 is:
def geometricSeriesSum(x, n)
sum = 0
i = 0
while i <= n
prod = 1
j = 0
while j < i
prod *= x
j += 1
end
sum += prod
i += 1
end
return sum
end
Which is, from a Ruby standpoint, a mess.
In Ruby, you'd most likely write something along the lines of:
def geometric_sum(x, n)
(0..n).inject(0) { |sum, i| sum + x**i }
end
or use Enumberable#sum directly.
Cheers,
Antonio
- --
http://antoniocangiano.com - Zen and the Art of Programming
http://stacktrace.it - Aperiodico di resistenza informatica
http://math-blog.com - Math Blog: Mathematics is wonderful!
This is always a bad sign. Even between two languages as similar as
Java and C++ having the same book in versions for each language means
one of two things:
1. The code involved is so trivial it is of little value.
2. One (or both!) of the languages are getting short shrift in
terms of proper, idiomatic use.
Given that Ruby is hugely different from Java and C++ I'm guessing
without bothering to check that the book is a waste of the Ruby
programmer's time. I base this opinion on experiences with a line of
books that purported to teach algorithms and data structures for Pascal,
C and C++. The only one that got decent treatment of the three was
Pascal (the original book, apparently). The remaining two got clumsy
translations that worked against the languages' core idioms.
···
On Sat, 2008-04-26 at 18:03 +0900, Laurent Julliard wrote:
Note: The same book for JAVA and C++ was published on paper by Wiley.
--
Michael T. Richter <ttmrichter@gmail.com> (GoogleTalk:
ttmrichter@gmail.com)
I can see computers everywhere - except in the productivity statistics!
(Robert Solow)
Laurent Julliard wrote:
Yesterday I cam across a Web page mentioning this book on "Data Structures and Algorithms with Object-Oriented Design Patterns in Ruby" by Bruno R. Preiss.
brpreiss.com
I'd like to know if anyone has read this book with care and has an opinion about it? I spend an hour or so on it and was under the impression that the content was good but that the source code of the examples look a bit too Java-ish.
Note: The same book for JAVA and C++ was published on paper by Wiley.
Thanks for you comments.
Laurent
This comes up fairly often on the list. I can't say I've read *any* version of it in depth, but there are better books available on similar subjects in just about any (programming) language you can name.
For object-oriented design patterns in Ruby, your best bet is Russ Olsen's _Design Patterns in Ruby_. I don't know if there's a good book on data structures and algorithms in Ruby, though. Data structures and algorithms are often explored in a language-independent manner, and often using the "natural" recursive formulations. Translation to specific programming languages is left as "an exercise for the student." 
Antonio,
Thanks for your feedback. I reviewed a couple of Ruby source files and the code was not as bad as the one you spotted. Obviously the entire code needs to be rewritten if one want to make a good Ruby book out of it.
I was however under the impression that this could be a good reference book for data structures and algorithm in Ruby now that more and more people (finally !) realize that behind Rails there is a really good programming called Ruby.
Apart from the escellent "Desing Patterns in Ruby" by Russ Olsen there is not much litterature on the subject.
Laurent
Antonio Cangiano wrote:
···
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Laurent Julliard wrote:
[...] I'd like to know if anyone has read this book with care and has an opinion about it? I spend an hour or so on it and was under the impression that the content was good but that the source code of the examples look a bit too Java-ish.
Hi Laurent,
versions of the book exist for C++, Java, C#, Python, Lua, Perl, PHP and
Ruby. The focus is clearly on the algorithms and the code is just
adapted for the given language. It's not idiomatic Ruby.
While idiomatic C++, Java and C# are roughly similar, this is not the
case when you also consider Ruby, Perl or Python.
For example, Program 2.6 is:
def geometricSeriesSum(x, n)
sum = 0
i = 0
while i <= n
prod = 1
j = 0
while j < i
prod *= x
j += 1
end
sum += prod
i += 1
end
return sum
end
Which is, from a Ruby standpoint, a mess.
In Ruby, you'd most likely write something along the lines of:
def geometric_sum(x, n)
(0..n).inject(0) { |sum, i| sum + x**i }
end
or use Enumberable#sum directly.
Cheers,
Antonio
- --
http://antoniocangiano.com - Zen and the Art of Programming
http://stacktrace.it - Aperiodico di resistenza informatica
http://math-blog.com - Math Blog: Mathematics is wonderful!
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.8 (Darwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iEYEARECAAYFAkgS/ooACgkQqCqsu0qUj9RW0wCdEMU/N19SlCzXu6NGtiajyXND
DFUAoKHpNMC6C03oDClpYw9vq1pIYU/6
=w3TF
-----END PGP SIGNATURE-----
If you've done C, you've come across the the most important data structures for it: structs, unions, enums, arrays, pointers, linked lists
Well, really just knowing what of the standard types to use for what.
With Object Oriented programming (which can be done in C... just not gracefully) you get other things that are very useful and sometimes language dependent.
In particular collection or container classes that include arrays and structs but take things to a new level of convenience.
Hashes are commonly used with key-value pairs (some languages call them dictionaries or other names)
The most unique to ruby is the old Symbol class. Get the rest of Ruby and Symbol will make more sense, especially when and how it is useful.
Ruby's other unique feature is its ability to enumerate over its collection classes with great ease and power.
Beyond that, any data structures book will give you ideas.
Take a look at other people's code too.