Book Reviews

JavaScript: The Good Parts by Douglas Crockford

ISBN: 978-0596517748
Publisher: Yahoo Press
Pages: 176

JavaScript is probably the most misunderstood language ever. There are several reasons adding up. Some of them are deficiencies in the core language itself; JavaScript is full of loopholes, glitches and encourages a programming model based on global state. Other reasons are better blamed on incompatible browsers and their individual quirks over the years. Yet, they all affect the coding experience in JavaScript. I sure shared that experience during my initial encounter with JavaScript. Some years later, I was surprised to learn that JavaScript, even if camouflaged with curly braces, has its roots in Lisp. Even if never dove deep into it, I learned that there are parts of it that are interesting and expressive. Inside the mess most of us know as JavaScript there's a small, simple and elegant language waiting to get out. And Douglas Crockford has managed to identify and document it. His book is proof that great design is achieved by removing features rather than adding them. There's value in minimalism.

Despite being a short book, it covers a lot of information. Douglas Crockford prefers a functional programming style. Several of the flaws in JavaScript are mitigated through proper and careful application of functions and closures. For example, encapsulation is achieved through closures, both for implementation details and as a way to simulate a module system. JavaScript also has an interesting object system. For a programmer coming from a classical OO background it's probably strange at first. Crockford's approach is to embrace JavaScript's prototypal nature rather than trying to mimic class-based object-orientation. After all, it's a powerful paradigm allowing for interesting patterns of code re-use and highly dynamic programs (IIRC, Paul Graham implements a similar object system as a case study in his brilliant ANSI Common Lisp). After my initial pass though the book I found that I've come to appreciate the language. Its syntax is simple with relatively few rules (although a lot of reserved keywords). It contains the components needed for expressive solutions (closures, higher-order functions, an object system). And finally it's low on syntactic noise.

I bought this book in order to get up to speed with JavaScript. While I do have some programming experience in it, I never spent enough time with it to understand its quirks and idioms. Those are the parts of the learning experience that takes time. Sometimes we never even get there (believe me, I know after +10 years in the C++ trenches...). With this book, Douglas Crockford saved me a lot of precious time. JavaScript: The Good Parts is exactly the kind of technical book I like. It's short, yet contains a tremendous amount of information. It's accessible, yet deep enough to keep as reference. Further, the organization of the material is exemplary and the code is well-written, at times even beautiful. If you have any interest in JavaScript this is the book to read. It's that good. And if you have a background in functional programming it will be a pleasant path towards idiomatic and powerful JavaScript.

Reviewed April 2012