Book Review: Building Dynamic Web 2.0 Websites with Ruby on Rails

Massive interest in Ruby on Rails over the past few years was quickly mirrored in book sales. Early entrants like the (near definitive) Agile Web Development with Ruby on Rails were break away hits in a world that usually sees modest sales of each title. It’s not surprising a lot of people wanted to get a share of that market, and the range of Ruby and Rails titles has exploded, with an unsurprising dip in average quality.

This latest title from Packt sits somewhere very low down the quality scale. An unfocussed volume, it purports to introduce the ruby language and show how to get up and running with a simple buzzword-laden Rails application, but does a distinctly inadequate job on both counts. Any moderately experienced rubyist would worry at seeing code like:

class Tale
  @author
  @genre
  @tale_body
end

recommended as the way to define a class with three attributes, rather than the more succinct, idiomatic and functional:

class Tale
  attr_accessor :author, :genre, :tale_body
end

(For those unfamiliar with ruby, the former will define attributes but not accessors for them. The latter will define the attributes and its accessors and is the recommended approach for public attributes)

That example occurs early on, and as the book progresses it is hard to shake the sense that the author isn’t sufficiently familiar with the idioms and best practices of the Ruby and Rails communities to be introducing either the language or the framework. When working with a framework as dependent on conventions and opinions as Rails, a failure to grasp the idioms is a serious problem.

It would be hard to recommend this book even if there weren’t many superior titles available. Newcomers to Ruby and/or Rails would be far better with any of several alternatives. Beyond that, while packt have published a number of excellent titles, the publication of this book should be taken as a reminder that there is no consistent quality control over the books they publish and buyers should research carefully before buying one.

Disclaimer: I was sent a copy of this book for review by the publisher. You can find it at packt, amazon US, amazon UK and all sorts of other places.

Tags: , , ,

2 comments

  1. I think there’s more to this –

    class Tale
    @author
    @genre
    @tale_body
    end

    These will not define attributes they way you think they should. When the Ruby interpreter reads these lines, “self” at this point is the *class* Tale, so these attributes will be defined as instance variables of the class object Tale. This is a far cry from

    attr_accessor :author

    because this will not only define an *instance* variables for objects of type Tale named @author, but also an instance method to mutate these variables.

    To further explain this consider the following example –

    class Tale
    @author = “Test”

    def self.author
    @author
    end

    attr_accessor :author
    end

    (In the IRB)

    >>t = Tale.new
    => #
    >>t.author = ‘Raju’
    => “Raju”
    >> t.author
    => “Raju”
    >> Tale.author
    => “Test”

    If that is the code in the book thats pretty sad. Thanks for the review. I now know to avoid this one.

  2. Thanks for the comment Raju. The fact that the first piece of code won’t define attributes the way attr_accessor will was what I was getting at, so sorry if that wasn’t clear. The author of the book implies that the first and second code examples are equivalent, which was very worrying if he’s being presented as a Ruby expert.