book report: Eloquent JavaScript

I picked up Marijn Haverbeke’s Eloquent JavaScript upon a friend’s recommendation and started reading it.

Here are some good points about the book: it takes on JavaScript from the perspective of a general purpose language, and not primarily about the web. The strongest part of the book are the many extended examples throughout the text. One of the first extended examples is a text-processing application. Another is a fairly sophisticated discrete simulation of a terrarium, the sort of thing reminiscent of a World-style program. Another includes a Sokoban implementation that uses DIV elements to present the game board. A person reading this book will come out pretty convinced that JavaScript can be used for Real Things.

Unfortunately, my reading picks up a few criticisms for the presentation and material. The book makes the motions of being an introductory text, with its first chapter talking about assembly, and how programming languages make our lives easier… but it doesn’t follow up. One of the major problems is that the book follows a grab-bag approach. Many books mistake “place an chapter at the beginning that enumerates all of the language features we’ll be using for the rest of the text” as beginner-friendly. This book commits that mistake: many chapters are a collection of language feature upon language feature.

Because of that grab-bag nature, some subjects are discussed with no satisfying depth. There are about two paragraphs of text about unit tests frameworks, and then no further mention of them. There are a few paragraphs talking about XMLHttpRequest, but no discussion about the significant implication of writing programs in asynchronous style, which really can be confusing for the beginner. The text treats these subjects as afterthoughts.

The subtitle of Eloquent JavaScript is: “A modern introduction to programming”. But it’s not really a good introductory text, nor is it a reference. The target audience that the author is writing towards is the programmer who has previous experience with some other language like Java or Perl…. but in my opinion, the best audience for this text is the JavaScript programmer! If one came into the book with a rudimentary knowledge of JavaScript, this book is great because it shows how to use JavaScript in anger. You can tell the author actually uses JavaScript as a working language, and that enthusiasm comes through in the text.

The programming style in the book unfortunately rolls right into some potholes in JavaScript. The use of “==” is persistent throughout the book. In the discussion of function closures, the text uses toplevel function declaration, as opposed to function expressions. This is a no-no! (See: http://javascriptweblog.wordpress.com/2010/07/06/function-declarations-vs-function-expressions/ for the details of why you’d want to avoid function declarations within the innards of a function.)

The use of “for (var …)” is also unfortunate, and there are bugs in the text involving it. Page 120, for example, does the following:

for (var i = 0; i < 10; i++) {
    for (var i = 0; i < 20; i++) {
        ...
    }
}

which doesn't attract the eye of someone coming from a sane language, but does strike immediate alarms to one sensitive to the weirdness in JavaScript.

This book is the kind of thing I love to read: a from-the-battlegrounds discussion on how to use a programming language in anger. It's not one of the phone-book sized tomes meant to take up bookshelf space: it's alive, with a good heart, but with some misssteps. What makes me pause is this: I know that I can make (and have made!) the same kind of mistakes that Marijn makes with regards to writing an introductory text. I hope future revisions fix the issues.

2 thoughts on “book report: Eloquent JavaScript

  1. A big-big plus you didn’t mention is that the html version is fully interactive, you can run and modify the examples right there.
    It would be nice to see the “How to Design Programs”, for example, powered with your Whalesong…

    • Yes, this is true! I focused on the dead trees (or more accurately, e-book) version of Eloquent JavaScript. I see that the web site has slightly different content, so my book report really only applies to the book, not the web site.

      About HtDP + WeScheme… yes, that’s on the TODO list.

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>