[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Has anyone read this book?

Laurent Julliard

4/26/2008 9:04:00 AM

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

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

4 Answers

Antonio Cangiano

4/26/2008 10:06:00 AM

0

-----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://antonioca... - Zen and the Art of Programming
http://sta... - Aperiodico di resistenza informatica
http://mat... - Math Blog: Mathematics is wonderful!
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.8 (Darwin)
Comment: Using GnuPG with Mozilla - http://enigmail....

iEYEARECAAYFAkgS/ooACgkQqCqsu0qUj9RW0wCdEMU/N19SlCzXu6NGtiajyXND
DFUAoKHpNMC6C03oDClpYw9vq1pIYU/6
=w3TF
-----END PGP SIGNATURE-----

Laurent Julliard

4/26/2008 1:11:00 PM

0

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://antonioca... - Zen and the Art of Programming
> http://sta... - Aperiodico di resistenza informatica
> http://mat... - Math Blog: Mathematics is wonderful!
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.8 (Darwin)
> Comment: Using GnuPG with Mozilla - http://enigmail....
>
> iEYEARECAAYFAkgS/ooACgkQqCqsu0qUj9RW0wCdEMU/N19SlCzXu6NGtiajyXND
> DFUAoKHpNMC6C03oDClpYw9vq1pIYU/6
> =w3TF
> -----END PGP SIGNATURE-----
>
>


M. Edward (Ed) Borasky

4/26/2008 2:00:00 PM

0

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.
>
> http://www.brpreiss.com/bo...
>
> 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." :)

John Joyce

4/27/2008 2:53:00 PM

0

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.