From: Laurent Julliard Date: 2008-04-26T22:11:21+09:00 Subject: Re: Has anyone read this book? 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----- > >