found drama

get oblique

review: Learning JavaScript Design Patterns

by Rob Friesel

Learning JavaScript Design Patterns by Addy OsmaniGoodreads.com has a community guideline that states that reviews must be about the book, and not about the author. Now, I happen to agree with the spirit of this guideline, but I also feel like that guideline gets a little fuzzy when you’re looking at non-fiction, and especially fuzzy when you’re talking about technical books. I mention this because this provides the appropriate frame of reference for what I’m about to say next: that I was disappointed in Addy Osmani’s Learning JavaScript Design Patterns (O’Reilly, 2012), but that most of my disappointment is because I hold him in high esteem, and as such was expecting so much more from this book.1 What was I expecting? A deep dive into how the classic “Gang of Four” design patterns can be (and are) applied to JavaScript development. But (and here’s where it gets weird) that’s also exactly what Osmani delivers. So why the disappointment? Because it felt like a compilation or round-up of blog posts on the subject.

In other words: it is a Greatest Hits album–if someone made a Greatest Hits album of blog posts from JavaScript pedants.

On the surface, many of my quibbles with the book seem like nit-picks:

  • The first eight chapters seem like they could have been rolled into one;
  • The section on namespacing patterns seems like it should have been its own stand-alone chapter, and not “jammed in” with the jQuery plug-in design patterns; and
  • what is with the single-page final “Conclusions” chapter?2

But I feel like these things are important. The structure of the book is important. How the information flows from one chapter to the next is important. The top-level chapter titles that you’re scanning in the table of contents are important. As I finished the book, it seemed to me that there was important information in there that was otherwise buried or obfuscated. If you didn’t know to look at sections within the chapter (or else weren’t patient enough to do so) then you might never know that there was a comprehensive discussion of namespacing patterns embedded within the discussion of jQuery plugin design; nor would you know that the “JavaScript Design Patterns” chapter was a (nearly) exhaustive walking tour through the Gang of Four’s patterns as they align with JavaScript-based software development.

I don’t place all of the blame on Addy Osmani for this, though. As I pondered my disappointment, I realized that his editors probably phoned it in with this one. Though some effort would be required to restructure the book, I think there was some easy guidance they could have given about restructuring the book to make it easier to bring out the highlights; but they just didn’t bother. Even if we give them the benefit of the doubt and assume that they meant for it to be published this way, I maintain that they half-assed the editing;3 for example:

  • The heading levels did not always have a clear correspondence with the level of importance for that section;4
  • The 2d object property notation on page 210 which (as it’s written) is clearly invalid JavaScript;
  • The multiple (multiple!) instances where (unescaped!) double-quotes are used within double-quotes–and how the syntax highlighting in the text even gives this away as a syntax error; and
  • Speaking of syntax highlighting, how it’s applied inconsistently throughout the electronic version of the book.

Like I said: they really phoned in the editing.

Now, there is a highlight reel here. There is plenty of useful content within the book–and this comes back to my original statement about feeling let down because of how much respect I have for Osmani. As anyone who reads Osmani’s blog (or his guest posts around the web, or his screencasts…) knows–he has a terrific pedagocial streak, and it’s clear that he enjoys helping people learn, and that he’s particularly adept at helping them learn to be better front-end developers. Throughout the first eight chapters,5 he does a fantastic job of defining what constitutes a pattern, of explaining why we (as front-end developers) should care about and study design patterns, and of what makes something an anti-pattern. Chapter Nine (the “walking tour” of the Gang of Four patterns) has the right balance between discussing the theoretical details behind a given pattern, and an illustration of its practical application. The most critical follow-up to Chapter Nine is found in Chapter Twelve, which essentially takes jQuery and uses it as a case study for those design patterns in action. Lastly, you can think of Osmani as providing a curator’s role with this book; there are many places in the text where he is citing work from others as either illustrating a particular facet of a design pattern, or else as building on it in some important way.6

And/but I also think that for getting the maximum value out of this book, you need to be a part of the right audience. In the preface, Osmani writes that the target audience is “professional developers wishing to improve their knowledge of design patterns and how they can be applied to the JavaScript programming language” (pp. ix). He assumes that you have a good intermediate knowledge of JavaScript to begin with (“You do know what a closure is, right?”) but not necessarily that you are “advanced”, and not necessarily that you have made a formal study of computer science.7 That being said, his statement that the book is targeted at “professional developers” seems a bit broad to me. A non-trivial proportion of the text has jQuery as its focus,8 which leads me to conclude that the book is targeted more at front-end developers that (for better or worse) lean heavily on the jQuery for their heavy-lifting.

Putting all of this together, I believe that if I were forced to choose, I would recommend Stoyan Stefanov’s JavaScript Patterns9 over Osmani’s JavaScript Design Patterns. Don’t get me wrong: if your bookshelf as room for both, then it’s worth it to explore both; each covers subject matter than the other does not, but in the places where they overlap, I find that Stefanov’s book rings a little bit more rigorous. Osmani’s book seems a bit more current with respect to citing specific technologies, but that also suggests to me that it will feel out-dated just a little more quickly.

★★☆☆☆

Disclosure: I received an electronic copy of this book from the publisher in exchange for writing this review.

UPDATE: (9/17/2012) It seems I have not been following Osmani’s work as closely as I thought, or else I would have known that this review was for the O’Reilly version of what has already been available for free online for quite some time. That being said: I maintain that the O’Reilly version is a poor conversion of the online resource;10 but the online version seems to be easier to recommend.

UPDATE: (10/30/2012) Addy Osmani’s response in the comments of the Goodreads.com version of this review.

  1. Perhaps that’s the price of success? That the people that admire you wind up feeling let down when you deliver something that’s… Only average? Not mind-blowing? There’s a part of me that thinks I’m being unfair or too harsh, but at the same time… Sometimes you need to hold folks to high standards? []
  2. Granted: I’ve dinged other books for not having a “concluding” chapter, and for otherwise ending abruptly while wrapping up some other subject (Sarrion’s jQuery UI comes immediately to mind, which I’ve previously reviewed)–clearly I would rather have a weak “concluding” chapter than no concluding chapter at all. So I’m kind of being a hypocrite here. Kind of. []
  3. Mostly the technical editing; but it seems like the copy-editing suffered a bit as well. (My heart sank a little bit when I saw the second ‘k’ in Nicholas Zakas’ name in the reference section.) []
  4. If we assume that a chapter’s title is an H1 heading, major sections are an H2, and so on down the list, then I would submit that there are numerous examples throughout the text where we have H2-level headings that seem like they should be H3 or below. E.g., how “Pseudoclassical Decorators” and “Decorators with jQuery” are both H2 level headings, but feel like H3 level sub-sections to “The Decorator Pattern” section; e.g., the H2 level “Namespacing Patterns” section that (in my mind) really should mark a whole new chapter in its own right. []
  5. Again: those first eight chapters really ought to have been formed up like Voltron into one. []
  6. And here is where recipients of the ebook version may be better off. I’m not sure how the links and references appear in the print book, but the ebook has clickable links to blog posts and other websites. Which is great. Thumbs up to that. []
  7. Which, thank goodness for that, since so many of us front-end developers are self-taught “liberal arts majors drafted into web developer service during the dotcom boom”. (Tip o’ the hat to Eric Miraglia for that quote from his foreword to Nicholas Zakas’ Professional JavaScript for Web Developers (2nd. Ed.).) []
  8. I have mixed feelings about this part of my critique. On the one hand, jQuery is a prevalent (pervasive?) library used by a huge number of front-end developers. And for better or worse, that library is synonymous with JavaScript as a whole to many developers. That being said, it seems disingenuous to call the book “JavaScript Design Patterns” when you’re dedicating two of your most lengthy and substantial chapters to that library. Perhaps the “Get Out of Jail Free” card here is that (1a) one of those chapters is really more of a case study and (1b) that so many folks are familiar with the library makes it a good case study because it’s familiar and also (2) if that helps these lessons reach and resonate with your target audience, then that’s probably a good thing. []
  9. I reviewed Stefanov’s book rather positively back in 2010. (Link.) []
  10. Which has the Namespacing Patterns section at the right heading level. []

About Rob Friesel

Software engineer by day, science fiction writer by night. Author of The PhantomJS Cookbook and a short story in Please Do Not Remove. View all posts by Rob Friesel →

Leave a Reply

Your email address will not be published. Required fields are marked *

*

*