Monday 31 May 2010

JavaScript: The Good Parts

The reader of "JavaScript: The Good Parts" by Douglas Crockford will get a very good idea of why JavaScript is considered a runt among programming languages. Crockford does his best to model good programming patterns and style in JavaScript. It is unfortunate and telling that the book is so thin. Crockford neither pulls his jabs at the language nor dumps on it unfairly, but gives a clear rationale for his opinions.

Like JavaScript, the book is more sure of what it is not than of what it really wants to be. Readers should read the preface seriously before going further -- but ignore the contradictory second sentence stating it is for programmers working with JavaScript for the first time. The book will interest language nerds, but it really should be read by intermediate JavaScript programmers who spend too much time debugging code they should never have written.

The short chapters make the book a relatively quick read, despite the somewhat advanced level of the material compared to other JavaScript books. Upon first glance at the size of the book, I was reminded of The Little Schemer (a tutorial on the Scheme programming language). Crockford's writing is easy to read, as if you were collecting thorough notes over a long series of lunch time talks. Incidentally, the structure of the book is unlike "Little Schemer" but Crockford does touch on functional programming techniques.

This book has a strong overtone of frustration with JavaScript. That isn't a criticism of Crockford, but sprinkled throughout the material are the tell-tale signs of what could have been, or should have been, but can never, ever be. It truly gets to a head in Chapter 9, titled "Style", in which 11 paragraphs in three pages start with "I". It is personal for Crockford.

Readers should be aware that there is virtually no error checking in the code. While omitting error checks is a common practice in trade book code samples, Crockford is making a point of illustrating good coding practice. The absence of a disclaimer is odd, but several of Crockford's examples do deal specifically with faulty conditional expressions. Take his warning in the preface to heart again here: "JavaScript: The Good Parts" won't tell you everything you should be doing to write good code.

JavaScript: The Good Parts is not a real reference, but if you do sporadic JavaScript programming it may be a book you will pick up again several times. That's because it is small enough and concise enough to act as a quick reference to the stuff that really is worth using, and some of the parts that really are best avoided.

No comments: