[Review] JavaScript: The Good Parts

As I mentioned in my Working With JavaScript post I’ve started on a new project that’s going to be pretty heavy on JavaScript.  Since I’ve been away from JavaScript for so long I wanted a language refresher but didn’t want to start from scratch.  What I needed was a good book to reactivate those long neglected neurons that store all of my knowledge of the language.  I’ve heard good things about JavaScript: The Good Parts by Douglas Crockford since it was published in 2008 and it was well reviewed on Amazon so I thought that would be a good place to start.

After giving the book a fairly thorough read (I skipped the chapter on Regular Expressions) I have to say that I was disappointed.  Now don’t get me wrong, the book introduced me to a few patterns I hadn’t encountered or thought of before.  It also helped me accomplish my goal of getting reacquainted with JavaScript and reminded me of a few things like the === and !== operators.

I don’t mean to detract from the author’s knowledge of JavaScript.  To the contrary, Mr. Crockford is widely regarded as one of the world’s foremost authorities on JavaScript.  Nor do I mean to sound like the book was entirely bad because it really does have plenty of good information.  Perhaps it’s just testament to the dual nature of the language having both really good parts and really bad parts but this book seems to follow that pattern.  Parts of the book are truly informative but there are other parts that fall flat and really hurt the overall quality.

For me, the most value came from the discussions about:

  • Properly handling data hiding through closures.
  • Properly handling inheritance.
  • Working effectively with arrays.
  • Using subscript notation rather than dot notation to avoid eval.
  • The custom utility methods such as Object.createObject.superior, and memoizer.

Many of my issues with this book stem from some statements in the preface:

[The book] is intended for programmers who, by happenstance or curiosity, are venturing into JavaScript for the first time.

This is not a book for beginners.

At first glance these quotes seem contradictory.  I understand that it is intended for experienced programmers just starting out with JavaScript but if that is the case why does the book spend time explaining what objects can be used for, defining variable scope, defining inheritance, and defining recursion? Aren’t these basic concepts in software development that experienced programmers should already be familiar with?

This is not a reference book.

This quote is misleading. Sure, JavaScript: The Good Parts isn’t a comprehensive reference of the entire JavaScript language but not a reference book at all?  Chapter 8 is a listing of methods on the built-in objects, Appendix C is a JSLint reference, and Appendix E is a JSON reference.

Including the appendices and index the book is only about 150 pages long but I found it to be full of fluff.  It really seemed like the author was struggling to reach 150 pages.

  • Chapter 8 is essentially a condensed restating of everything that came before in that it is a listing of the “good” methods of the built-in objects.  Adding length to this chapter is an example implementation of Array.splice. If JavaScript provides it and it’s one of the “good parts” why do I need an alternative implementation?
  • Chapter 9 is four pages describing the coding conventions used in the book (shouldn’t this have been at the beginning?) and why style is important (shouldn’t experienced programmers already be aware of this?).
  • Chapter 10 is two and a half pages about the author’s inspiration for writing the book and why excluding the bad parts is important.
  • Appendix C: JSLint seemed really out of place.  The preface insisted that the focus of the book was exclusively on the JavaScript language but a utility for checking for potential problems in code gets a nine page appendix?
  • Appendix E: JSON explicitly states “It is recommended that you always use JSON.parse instead of eval to defend against server incompetence,” but then spends the next four and a half pages on a code listing showing an implementation of a JSON parser! If it is recommended that JSON.parse always be used why include the listing?
  • Railroad diagrams are useful but many of them take up huge amounts of space.  The fact that they were repeated in Appendix D just stretches the length of the book another 10 pages.

Although the book has a repetitive, drawn-out structure I still think the information it contains is valuable enough to make it worth reading. As a supplement I highly recommend watching Mr. Crockford’s Google Tech Talk covering much of the same material.  The video covers many of the book’s high points and even touches on some topics not included in the book.  In some ways I actually think the video is better than the book even though it doesn’t get quite the same amount of detail on some of the topics.

Advertisements