Book Review: The Ruby Programming Language

For a long time now Dave Thomas Programming Ruby (aka. The Pickaxe) has been the standard in the Ruby community as the book to learn Ruby from. Unfortunately the Pickaxe is not the best programming book ever written. In fact, its bulk and slowness almost killed my inspiration to learn Ruby. I respect Dave Thomas a lot for what he does for the Ruby community but the Pickaxe and I just did not click.

Since I didn’t find the Pickaxe to be excellent reading material, I had been eagerly anticipating David Flanagan’s The Ruby Programming Language to come out and unseat The Pickaxe as the de facto book to recommend to newcomers to Ruby.

I am happy to say that The Ruby Programming Language did not disappoint. I picked up this book solely expecting to just review it since I already comfortable programming in Ruby. However, once I started reading the book I found myself frequently learning things about Ruby that I didn’t know before. Not like little things either like, “oh that’s interesting”. I’m talking significant things like “holy crap that’s sweet”.

This book covers both Ruby 1.8 and Ruby 1.9. Initially this concerned me because as impressive as it is, it must have been quite a headache for the authors and was not sure how they were going to pull it off. It turns out to be pretty much a non-issue. The authors make a note of what is 1.8 or 1.9 only and it does not disturb the flow of the book since it doesn’t come up too frequently. I do hope though that after Ruby 1.9 stable is released they upgrade the book and tear out all the 1.8 specific material. Since I currently use 1.8 on a daily basis I don’t mind having 1.8 material in there but after everything has shifted to 1.9 it would be rather irksome.

The style of the book is fairly straightforward. It starts with an introduction to how Ruby programs work and then goes into an explanation of Ruby datatypes and objects. The later chapters cover advanced topics like reflection and metaprogramming. The authors opted not to go the tutorial route, which I think, was a good approach since the book is not designed to be an “intro to programming” text.

In the preface of the book, the authors state:

[The Ruby Programming Language] is loosely modeled after the classic The C Programming Language by Kernighan and Ritchie and aims to document the Ruby language comprehensively but without the formality of a language specification. It is written for experienced programmers who are new to Ruby, and for current Ruby programmers who want to take their understanding and mastery of the language to the next level.

O’Reilly is hoping that The Ruby Programming Language becomes the equivalent of K&R’s The C Programming Language for Ruby and I hope it succeeds. I think that every language needs their own K&R book for people to turn to as the definitive authority. That’s something that I feel like the Java programming language never had and it creates something of a hurdle when browsing for a Java book.

The third edition of the Pickaxe is in beta and will be coming out soon. I really hope it makes a strong showing when it hits the press because after the bang-up job Flanagan and Matz did with The Ruby Programming Language, there is no reason to look at the Pickaxe till then.

Ruby-Poker 0.2.4

I just pushed out another release of the ruby-poker gem. The only change in this release is some code changes to achieve compatibility with Ruby 1.9.

Initially I had thought that I would not need to change anything for 1.9 because ruby-poker-0.2.2 installed and ran through some quick examples without any trouble. However, I was saved by my test suite when it quickly exposed a problem where I was calling each on a String object. The each method was removed from String in 1.9 so I made a quick change to work around it and once again I’m seeing nothing but dots.

Rp Unit Tests Pass

Eager Loading with Ultrasphinx

Ultrasphinx is a great Rails plugin that wraps around the Sphinx full-text search engine. I am using Ultrasphinx to handle search queries on a personal project I’m working on and I ran into a situation where I wanted to eager load associated models for my search results. The method for doing this is not well documented so I’m going to step through how to add eager loading to your Ultrasphinx searches.

I am actually going to show two ways to do this. The first is the way that Evan Weaver, the creator of Ultrasphinx, recommends and the second way is the create a simple plugin that extends the Ultrasphinx plugin. The second way is my favorite because it provides the cleanest integration in my opinion but I’m going to demonstrate both methods so you can choose for yourself.

Read more

Ruby-Poker 0.2.1

Ruby-Poker 0.2.1 is an incremental update over the 0.2.0 release. The biggest change is the addition of the << and delete methods to the PokerHand object. Making it possible to add and remove cards from a hand without creating a new PokerHand object.

require 'rubygems'
require 'ruby-poker'
 
hand.PokerHand.new("3d 3s 7h 7d")
hand.to_s                   # => "3d 3s 7h 7d (Two pair)"
 
hand << "7c"
hand.to_s                   # => "3d 3s 7h 7d 7c (Full house)"
 
hand.delete("3d")
hand.delete("3s")
hand.to_s                   # => 7h 7d 7c (Three of a kind)"

I’m always in the process of adding documentation to ruby-poker. At this point the majority of the public facing methods of the PokerHand and Card classes have been documented with examples. The ruby-docs are available online at http://rubypoker.rubyforge.org/.

Rails has a low learning curve? Hardly. You need to know Ruby

Ruby Required

Ruby on Rails is often (incorrectly) billed as the framework that makes web development easy. Unfortunately a lot of people take this to mean “Anyone can make a web site with Rails” or “You can get started with Rails in 15 minutes“. Unfortunately neither is the case but regardless hundreds of thousands of people1 are flocking to Rails to start making a web app for everything under the sun.

These people learn in hurry that Rails is actually quite a large beast2 and jump right into working with Rails without taking time to learn the programming language that Rails uses… Ruby. Almost like Ruby doesn’t exist. If I had to guess I would say people coding Rails apps without actually knowing Ruby has inevitably lead to the Rails community’s pseudo status as a ghetto.

I must confess, I was one of the Rails coders who didn’t know Ruby when I first started with Rails. Very few people who come to Rails known Ruby due to Ruby’s limited popularity before Rails came along. For about the past 7 months I have been trudging along, learning more about Ruby every day3 and the code I write for Rails projects now is much better. Ruby programming constructs like blocks, lamba, proc, etc are fairly advanced topics that I am probably only beginning to comprehend.

Most people might think it is obvious that you would need to know a framework’s programming language before you started using the framework. Certainly you would not attempt J2EE development without first knowing Java. For some reason this has not always been the case with Rails.


  1. Instant Rails has been downloaded over 400,000 times. 

  2. The Rails Way which contains everything a Rails developer needs to know about Rails is 912 pages. 

  3. Largely thanks to Project Euler

← Previous PageNext Page →