Author: Michael Fogus
Even if you do want to use Underscore this might not be the book for you because it doesn't really explain anything about the library. In fact it doesn't even make clear when a function is being used from the Underscore library. You are reading along and all of a sudden you meet:
Yes this is a use of an Underscore method, but you aren't warned and what it does isn't discussed. The book continues in this way - simply presenting examples and not explaining them. You are supposed to work out what is going on by knowing what the code does. This isn't quite the same thing as understanding the features and facilities that a library offers and then seeing how they might be used.
collects a composite value from the incremental results of a function supplied with an accumulation value and each value in a collection.
This is fine if you know what a reduction is all about and have met a function like reduce before. If you don't then you are going to have to work out what is going on from the examples. This could be made so much easier to understand.
Chapter 3 is an in depth look at scope and closure. Again the problem is that there are no helpful explanations of what something is. For example, dynamic scope is said to be useful and then we have some code that implements it - without the reader really having much idea of what is being implemented. It's like a puzzle you have to solve to understand what something is. Later the chapter goes into detail about closure but fails to notice the key relationship between scope, closure and the Function objects lifetime. Again it seems to make everything more difficult than it needs be.
Chapter 4 introduces the idea of higher order functions. It takes you through using functions as parameters and return values. There is a lot of discussion of how the ability to use functions in this way makes it possible to create functions that let you work in a different way. The issue of state and mutability is also introduced but you may not follow whey immutability is a good idea in functional programming.
The theme of higher order function continues in Chapter 5 about function building functions. This is where composition is introduced along with another look at mutability and using imperative styles in framework functions. To quote:
"This book is not about spewing dogma regarding the virtues of functions programming. I think that there are many functional techniques that offer ways to rein in the complexities of software development, but I realize that at times, there are better ways to implement any given individual part."
OK - but this is a book about function programming, right? And as such I think I for one would like to be exposed to some of the ideas that are being ignored. The problem is that the key ideas are hardly ever made explicit and when they are you could easily miss them.
The chapter then moves on to currying, which is a much more practical and directly useful technique than worrying about immutability. The problem is that once again you have to figure out what currying is from examples and difficult-to-follow explanations.
"A curried function is one that returns a new function for every logical argument that it takes."
I have no idea what this means and I already know what currying is. Later the distinction between currying and partial application becomes even harder to fathom.
Chapter 7 tackles the issue of purity and immutability, which given how important these ideas are probably should have been introduced earlier in the book. It makes the point that mutation is OK as long as it is used internally within a framework function that returns an immutable value. It also explains the connection between immutability and the way recursion can cover up the changes by making them on the stack. It is the core premise of functional programming that functions should behave like mathematical functions and this implies immutability.
Chapter 8 explains flow-based programming, i.e. how to create fluent interfaces like those jQuery uses and how this can be the basis for building functional programs. This flows into Chapter 9 where the idea of building systems without the use of class hierarchies is introduced. These final two chapters are perhaps the most interesting in the book, but as before it is difficult to pull out the pearls of wisdom because of the way the examples keep them hidden.
|Last Updated ( Saturday, 12 July 2014 )|