From: Antonio Cangiano Date: 2008-04-26T19:10:02+09:00 Subject: Re: Has anyone read this book? -----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-----