December 05, 2007

Posted by John

Tagged review

Older: RubyConf 2008 Suggestions

Newer: Ack, A Code Searcher

Book Review: Pro Active Record

Pro Active Record

Pro Active Record “helps you take advantage of the full power of your database engine from within your Ruby programs and Rails applications.” It is authored by Kevin Marshall, Chad Pytel, and Jon Yurek and published by Apress. For this review, I’ll start with the bad and then finish on a positive note.

The Bad

I feel the title of this book is very misleading. It should be “Learning Active Record” or “More Documentation for Active Record” or “On Your Way to Being a Pro in Active Record.” Why is a “Pro” level book teaching you how to set up your database in chapter 3. Heck, why is it talking about setting up your database at all? I would think that a book on the pro level would literally be chocked full of advanced code samples and such, not simply above average documentation for all the the methods in the Active Record module. Teach me how to model complex things. Start right off with an example of how to do something that you don’t learn in the first few months of rails.

There were a few places in the book where I felt there were contradictions with idiomatic ruby/rails and even with other parts in the book. For example, page 43 recommends not to use upper case database columns. I agree. Rails agrees. It doesn’t cause any harm but Ruby is case sensitive so it’s better to stick with lower. Also, upper case typically denotes constants and classes. Method names in ruby (and thus column names) should always be lower case, yet several places in the book use examples with column names in mixed case (ie: Account_Username instead of account_username).

Also along these lines, typically, method names are words separated by underscores (ie: my_method_name instead of mymethodname). More than a few examples in the book were multiple word methods or column names but didn’t separate with underscores.

I realize that I am being really picky and this seems kind of harsh but I see this book as a beginner to intermediate level and would hate for someone in that range to see something generally frowned upon in the community and unknowingly accept it as an “ok” practice.

The Good

Ok. Enough ripping, now on to the good in this book. First off, it reminded me of how Active Record is capable of handling locking by use of the lock version column. I had read this a while ago but forgot. Not too long ago I spent 30 minutes at the whiteboard coming up with a solution (purely for academic purposes), not thinking to see if Active Record handled this in any way.

Second, it had a few examples of how and when to use the straight up connection methods for executing raw sql (execute, insert, update, select_on, select_values, select_all, etc.; more on this on Josh Susser’s blog). Just yesterday, I used select_all to do some sql for the news archives area of Conductor, the CMS I am building at work for our University.

Third, it mentioned the convertible to csv gem/plugin which adds a to_csv method to your active record models in a similar fashion to the existing to_xml, to_json, etc. that you can do in Rails.

Lastly, it pointed out the uuidtools gem. I had forgotten about it.

Conclusion

I would recommend this book to someone who has some grasp on Active Record but wants to learn more about all the options it has. Don’t expect any complex examples but the book does work great as a documentation source for Active Record. It has a few more examples and explanation than the AR docs themselves.

Other Reviews

Don’t take just my word for it, check out these other bloggers who have written up reviews and make an informed decision.

3 Comments

  1. Great review, too bad I didn’t read it before I read ‘pro active record’.

    I seriously expected a more advanced book on how to hack ActiveRecord, how to get the best performances out of AR, benchmark to death, or even a better presentation of other solutions out there.

    However, I have to say that if you don’t know much about AR yet, it’s a great book! Don’t hesitate and go get a copy. (it will save you from spending hours going through the API doc)

  2. @Matt – Completely agree.

  3. Thanks for the link! Good review.

Sorry, comments are closed for this article to ease the burden of pruning spam.

About

Authored by John Nunemaker (Noo-neh-maker), a web developer and programmer who has fallen deeply in love with Ruby. More about John.

Syndication

Feed IconRailsTips Articles - An assortment of howto's and thoughts on Ruby and Rails.

Feed IconRails Quick Tips - Ruby and Rails related links.