Book Review: The Merb Way from a Rails Developer's Perspective
In December of 2008 the Rails team & Merb team announced that the two frameworks would be merging to form Rails 3. This came as quite a shock to many & reactions were rather polarizing. For Foy Savas the news raised the question of whether or not there would still be a place for his work-in-progress The Merb Way. After several weeks with the book & playing around with my first Merb app I am happy to say that I believe there is.
The Rails Way & Mastering an API
Obie Fernandez’s book The Rails Way was instrumental in taking my understanding of the Rails framework to the next level. When I began reading The Rails Way I was already productive with Rails but knew I was missing out on a lot of less publicized features.
The Rails Way gives you a top down perspective with a focus on how to use the API to make the most of the framework. Exploring the actual implementation is left up to you. The Merb Way takes a different approach.
The Merb Way: Design & Philosophy
The Merb Way is all about design. The best bits may be the sidebars that dig into the various design decisions made in Merb & the reasons behind them. This is stuff that you’ll never get from API documentation.
The book starts out with a pastie consisting of the full source of the initial Merb implementation. At barely three pages long it really illustrates how Merb distinguishes itself. It was built from the ground up to embody a philosophy of lightweight. The introduction does a great job putting this & other Merb philosophies such as speed & modularity into words.
Chapter one goes over the basics of the Merb stack from a high level. It covers the application layouts available & how to generate them. It breaks down the basics of what each component of the stack is responsible for as well as the various configuration bits that glue them all together.
I did feel that there was one major omission in this first chapter & that is coverage of the installation process. Before reading this book I had made one attempt to explore Merb and never got an application running due to various dependency conflicts. This was well before the 1.0 release & the process was much smoother this time but there was still a period of frustration where I was unable to get an application to boot up successfully. To be fair the clues needed to solve my problems were contained in the book but they were not obvious without some help from google. It would have been nice to have a section dedicated to common problems you might encounter getting up & running.
Grokking the Internals
The bulk of the content is a mix between in-depth exploration of source code & practical usage of the API. Foy does a great job of explaining this code without letting the discussion get dry.
The coverage of DataMapper was one of the highlights for me. As someone comfortable with ActiveRecord I always figured that I would just use that in a Merb project. Seeing how things like migrations & query construction/execution are handled in Merb quickly changed that attitude. There is some really clever code (the good kind) in here & I’m looking forward to drop in compatibility with DataMapper in Rails 3.
Yehuda Katz has written quite a bit about refactoring the Rails controller & view layers so I didn’t find these chapters to be as illuminating as the DataMapper chapter. Parts & Slices are two features I was excited to learn about. It turns out there wasn’t a whole lot of depth to these chapters, which I think is actually a reflection of the design decisions made on the controller level.
The chapter on merb-auth is a good way to learn how to add custom functionality to Merb. The plugin is designed to be extensible, following the example set by Merb itself.
Who Should Read It?
Foy makes several references to three separate types of developers this book is targeted towards.
- Application Developers
- Plugin Authors
- Framework Students
You will get the most out of this book if you fall into one of the later two categories. With Rails 3 approaching, I would encourage anybody who works with Rails to assume the role of framework student & give this book a look. There are some very cool things coming in Rails 3 that pull from the Merb design philosophy & I believe that being familiar with these ideas will give you an advantage as Rails 3 makes it’s way into production apps.
If you are curious about how a framework is designed this is the perfect book for you. I don’t believe there is another book out there that covers the design of a Ruby framework to this extent.
Because the content bounces back and forth between API usage & discussion of the internals I wouldn’t recommend this as a reference book for Merb development. That’s not to say it isn’t useful for that purpose however…
The Merb Way in Practice
After reading through the book I went back & tried to put my new knowledge into practice. I decided to build a simple contact list backend for the CKC United. I’m definitely not taking full advantage of all Merb has to offer but I wanted to see what it would take to get up to speed & productive working with Merb on a real project.
Aside from the installation issues mentioned earlier it was mostly smooth sailing. I did find the book to be a valuable reference even if finding the content I was looking for might not have been as straightforward as possible. There were a few spots where I had to resort to google but that is to be expected.
Conclusion & A Contest!
The Merb Way is definitely worth picking up if you’re even a little bit interested in framework design. Foy Savas is an excellent writer & presents the material with style.
I thought it would be fun to have a contest to give away my copy. If you’re interested in receiving a copy please leave a comment letting us know why you want to learn The Merb Way. It can be serious, funny, practical or creative. I will pick my favorite answer & send the book your way. I’ll also choose one runner up to receive a 35% discount from InformIT.
This is my first review & I plan to do more in the future so any comments on how I did & how I could improve are much appreciated!
Other Resources for Merb & Rails 3
- Merb Internals Handbook (with huge graphic of Merb stack)
- The Merbivore Wiki
- Yehuda Katz’s blog
- Ryan Daigle’s (covering Rails 3 changes)