Thursday, 27 November 2014

Book rant: Functional JavaScript by Michael Fogus

O'Reilly books generally are really good. Not this one. I got only to the 32nd page but by that time I had enough red flags that I can recommend to never ever touch this book except if you need something to burn on a cold Winter night. This was the final straw (quoted from the book):
var bFunc = function() { return this };
var b = {name: "b", fun: bFunc};
b.fun();
// => some global object, probably Window
The author uses this example to explain how the "self-reference semantics conflict with the notion of functional programming". Whatever that means. I really don't know what he meant and I will never know because the author doesn't get JavaScript. I had the same itchy feeling before this page; somehow the explanations are not clear, feels like the author himself doesn't "get it". I hoped that maybe the introductory sections don't try to explain what's going on and later in the book he does. Then I scanned the remainder of the book, just for the sake of this entry. No, he doesn't. Whenever he touches a topic that goes deeper than the conceptual level it's clear that he doesn't have enough understanding to explain it well. Or as the example above shows: sometimes he is simply wrong.

On a side note, and this is not the fault of the book, Underscore itself is a questionable functional library. It's a library that provides some higher order functions which resemble the ones used in real functional programming. But that's it. It's a shallow substitute and doesn't help you master thinking in functional programming. The guy in that video (Brian Lonsdorf) has an online video course. I haven't seen it yet, but I believe it must be a good one. However what I can strongly recommend is if you want to learn real functional programming in JavaScript go and read JavaScript AllongĂ© from Raganwald. For free if you wish. Then pay as much as you want to. Because that book is a piece of art. From somebody who does understand functional programming and does understand JavaScript.