Search This Blog

Tech Book Face Off: Agile Web Development with Rails 4 Vs. Ruby on Rails Tutorial

It's been quite a while since I've done a Tech Book Face Off, and that's because it's taken some time to get through this pair of books. Whereas most tech books can be read straight through, (even books on languages to get the gist of them, with a little experimentation thrown in) these books are meant to be worked through. They are both written in a tutorial style where they describe how to build an actual web site using Ruby on Rails. That approach makes perfect sense for a web framework like Rails.

I was really looking forward to both of these books. I'd heard lots of great things about Ruby on Rails Tutorial, and I was quite interested to see what working through a tutorial style book would be like. I figured the change of pace from conventional tech books would be refreshing (and it was). Then with Agile Web Development with Rails 4 I was anticipating another great read from Dave Thomas, a co-author of The Pragmatic Programmer - one of my all-time favorite programming books. Having David Heinemeier Hansson, the creator of Rails, as another co-author raised the bar even more.

As for Rails itself, I, of course, had very high expectations because of the vast amount of publicity and high popularity it carries in the web development community. Without knowing any other web frameworks to compare it to, I must say that I was impressed with how easy it is to make well-structured web applications quickly with Rails. Things did get a bit confusing at times because Rails does so much for you that it's not always clear how all the different parts of an application are connected together, but that may have also been due to the fact that I had no prior experience with how web applications are built. At any rate, it didn't take too long for everything to clear up after some experimentation.

Rails is an opinionated web framework that has very strict ideas about how a web application should be built. As long as you follow its lead and program in its style, development will be extremely smooth and you can focus on designing an awesome web application instead of figuring out all the minutiae of things like URL routing, HTML template processing, and database management.

So what is the Rails way? First and foremost, Rails conforms to the MVC (Model-View-Controller) architecture. The model is the encapsulation and organization of the data that your application uses and stores, i.e. the database, and Rails supports a clean ORM (object relational model) to most of the common databases in the industry, including MySQL, PostreSQL, SQL Server, SyBase, Oracle, and SQLite. The view is the representation of the data that can be consumed by humans or other computers. Rails can generate views in the form of HTML, XML, and JSON out of the box and more forms, like PDF, with plugins. The controller basically connects the model and the view with all of the logic and validation that's necessary for making decisions and computing results in the application.

There's a lot more to the Rails philosophy and architecture, but let's move on to the books.


Agile Web Development with Rails 4 front cover VS. Ruby on Rails Tutorial front cover

Agile Web Development with Rails 4


This book actually has three authors: Sam Ruby, Dave Thomas, and David Heinemeier Hansson (known in the Ruby community as DHH). Even with three cooks in the kitchen, the book has a consistent style and feel to it. There is an ongoing narrative about a client that you're working with to build a web store with a shopping cart. The story can get a bit cheeky at times but overall it's pleasant and lighthearted. DHH steps in periodically with sidebars that go into more detail on specific topics on the Rails philosophy, which was nice.

The first part of the book covers setting up the environment for Ruby and Rails. I had already set everything up by the time I read this book because I went through the Ruby on Rails Tutorial first, but I had done it with Rails 3.2 so I tried installing Rails 4.0 alongside for this book. It worked without a hitch. The second part is the tutorial section that goes through building an online book store with a product catalog, a shopping cart, order forms, confirmation emails, administrative accounts, and more. Everything was broken up into small, discrete tasks, or iterations in agile terminology. The last part goes deeper into the details of how Rails works under the hood with its major components: Active Record, Action Controller, Action Dispatch, Action View, and Migrations.

The tutorial section was great for getting your hands dirty with Rails right away. There's nothing like entering a few commands, writing a few lines of code, and seeing a web application come alive before your eyes. It quickly became apparent that most of the work in building a Rails app was spent writing the HTML and CSS templates, and most of the initial work of connecting the views to the database and getting the application operational was neatly handled by Rails. I'm sure to get a finely tuned application, more work would need to be done in the model and controller, but an impressive amount of work is already done for you.

Two things struck me about the tutorial. First, the authors assumed that if they mentioned some practice once, like checking code into Git after every iteration, the reader would then remember and use that practice from then on. I liked this approach of explaining things clearly and then focusing on new information instead of constantly reminding the reader and engaging in too much hand-holding. Second, even though this was an Agile book, not much space was devoted to TDD (test-driven development), and test-first development was hardly mentioned at all. I was surprised by this omission, but I'll talk more about that with the Ruby on Rails Tutorial.

What I liked most about this book was the Rails in depth section. I have trouble remembering how to use languages or frameworks unless I really understand how they work. This section gave me enough knowledge about Rails to really anchor my understanding of how all the pieces connected together, where to look for code, and which files to edit to accomplish different tasks. And the authors were able to lay all of this information out in about 150 pages so it was concise, focused, and extremely helpful. I would say the book is worth buying for this section alone.

Ruby on Rails Tutorial


Whereas Agile Web Development with Rails 4 was split between tutorial and explanation, this book by Michael Hartl is a full-on tutorial. It goes beyond Rails, expanding into many more areas of modern web development. In addition to Rails proper, it covers TDD with RSpec and Capybara, version control with Git, deployment to Heroku, Behavior-Driven Development with Cucumber, a number of other Gems, and a bit of SQL and JavaScript.

In this case the application you're building is a Twitter-like web site that allows users to log on, write short messages, view other users' messages, and follow other users to create an aggregate message feed. It's pretty much a no-nonsense guide to implementing all of the parts of a Rails application that makes a web application like this work, and it is superbly done.

The TDD work flow presented in the tutorial is very compelling. It was great to see how writing tests first can focus your programming efforts and improve productivity. It works best when you already have a good idea of what you're trying to do, so it won't be the right approach in all cases. But where you can write tests first, it's really slick, and a lot of tasks that you'll do in Rails will fall in that category because of the well-defined architecture of Rails applications.

The tutorial is not without its problems, though. What I found difficult about the tutorial format - and this is true of the second section of Agile Web Development with Rails 4 as well - was that it was distracting. While it was great to write code while reading the book because I could see immediately how to use Rails features and where different code should live, it also involved a lot of context switching between reading about features and writing code. If I made a mistake and tests started failing so that I'd have to stop and debug, or I went off on a tangent experimenting on something I found interesting, things could quickly get out of control, and I'd lose the thread of the book completely.

Another problem with the tutorial format was that most of the explanations were focused on how to implement the next part of the application. There was little in the way of describing the Rails features that were being used, how those features worked, and why everything was put together the way it was. The emphasis was all on getting the application features done, and I think that's a poor way to learn anything well. To really learn something so that you can use it effectively, you should understand why it works the way it does at a deeper level.

That critique may sound harsh, even damning, but that's not the case. I thought that as a tutorial Ruby on Rails Tutorial was exceptionally well written, and I enjoyed building up a fully functional Twitter-like application immensely. The issues I have with tutorials may not apply to you, so don't let that stop you from using this book. It's an excellent introduction to Rails that will get you up and running with a real web application in short order. I would recommend checking it out.

The Defining Differences


Both of these books do a great job of introducing Rails, but in slightly different ways. The Ruby on Rails Tutorial has you work through a more extensive (and I would say more interesting) application in its tutorial, while Agile Web Development with Rails 4 supplements a shorter tutorial with more in-depth explanations of the features, organization, and inner workings of Rails. Personally, I would have liked a treatment that presented a series of detailed explanations of how to use the different features of Rails and why they work, with a set of exercises following each chapter that would end up implementing a coherent application by the end of the book.

What I'm describing is essentially a textbook for Rails, but since that probably doesn't exist, I would have to pick Agile Web Development with Rails 4 as my preference. It does a better job of explaining what goes on in Rails under the hood, and I needed some of that to internalize how to use Rails and remember it more permanently. If you learn best from tutorials, and the more in-depth stuff is less important, then the Ruby on Rails Tutorial will serve you better. In either case, great books, and I really enjoyed writing my first Rails applications.

No comments:

Post a Comment