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: 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.

A release of Racket

Racket 5.1.2 came out recently, and I’ve been pretty happy using it so far. It feels significantly snappier than 5.1.1. It also looks like some of the graphical quirks I saw in DrRacket running under xmonad are fixed.

Documentation still needs some work, according to folks on Reddit. Although Racket has a lot of good reference documentation and quite a few tutorials, the meaty libraries like the FFI are missing the kind of treatment that the Guide provides for the basic language.

Lots of work to do!