Mini book review: Recipes With Backbone

Disclaimer: this is my first-ever book review on this blog! I’m not a javascript/HTML developer by trade so it’s not going to be a critical review or anything — just how I found reading it.

I’ve worked on a few web applications over the years, and I’m familiar with at least a couple of other MVC-style frameworks, but it’s all been .NET, and recently, all on the desktop. Only in the past few months have I attempted my first full-on browser-based javascript application, using the fantastic Backbone.js. The journey so far has been pretty bumpy, but I’m finally getting to the point where I’m comfortable enough with Backbone (and the javascript language itself) to really start being productive. But recently I’ve been starting to hit some complex situations that I’m not sure how to implement, and am struggling to find online. As well, I’m always on the look out for tips confirming the code I’ve already written is on the right track.

I stumbled across Recipes With Backbone book by chance from a blog post by one of the authors, where he was discussing how to implement default routes. I was a bit hesitant at first when I couldn’t find many reviews of it, but ‘advanced Backbone’ is a pretty new subject area (even to find on blogs) and it was cheap so I bought a copy. I am glad to say I was very satisfied with my purchase.

The book has 152 pages, and it took me a day to read on my Kindle. It covers:

  1. Writing Client Side Apps (Without Backbone)
  2. Writing Backbone Applications
  3. Namespacing
  4. Organizing with Require.js
  5. View Templates with Underscore.js
  6. Instantiated View
  7. Collection View (Excerpt)
  8. View Signature
  9. Fill-In Rendering
  10. Actions and Animations
  11. Reduced Models and Collections
  12. Non-REST Models
  13. Changes Feed (Excerpt)
  14. Pagination and Search
  15. Constructor Route
  16. Router Redirection
  17. Evented Routers
  18. Object References in Backbone
  19. Custom Events
  20. Testing with Jasmine

The book is based around a hypothetical online calendar application, analogous to Google Calendar. I use GCal a lot so it was nice to have familiar examples — some books use made-up applications that are unfamiliar or too vague (even a blog or a todo list could be designed in many different ways). But when examples are based based off a specific real-world application like GCal or Twitter then you already know how it’s supposed to behave and it simply becomes a matter of mapping that behaviour to the code examples on the page.

The book is structured as a series of enhancements to the calendar — starting with a plain jQuery $.getJSON() on a server-generated HTML page, just like we used to write in 2008. This was a good familiar starting point for me, before leaping into a basic Backbone structure and then refactoring it and adding more advanced behaviour.

The twenty chapters are each presented in a problem: solution format. They are very brief but I really liked this — they are clear, succinct, get straight to the point, and are very readable. Code is explained in 3-4 line chunks at a time, which fit well on my Kindle (which has a small screen and no colors). Overall I thought it was very good value for time spent reading.

For me, the book was valuable because:

  • It corrected some things I thought I already knew 🙂 like $(el) injection
  • It showed patterns for dealing with things like view deactivation and dangling event references (as a WPF developer this stuff gives me nightmares)
  • It showed how simply and elegantly difficult things like paging could be implemented
  • It suggested some neat things I hadn’t even thought about yet e.g. constructor routing

The book also includes a chapter on Require.js, which it presents early on as a foundation — chapter four — right after namespacing. I’m a fan of require.js and have no doubt it will soon become a standard requirement for any serious JS development in future. But right now it’s not widely supported and — in my experience — can cause a lot more problems than it solves. Unless you’re totally comfortable accepting the fact you’ll probably have to hack a lot of third party jQuery plugins just to make them work, I would not recommend require.js to beginners until the rest of the community catches up.

Regardless, Recipes With Backbone is still the single best text I’ve read on Backbone (aside from the Backbone docs themselves), and I’m looking forward to seeing what else these guys write. I would definitely recommend it to anyone wanting to take their Backbone skills to the next level. Go check it out and read the sample chapters here: http://recipeswithbackbone.com