Computing Reviews
Today's Issue Hot Topics Search Browse Recommended My Account Log In
Review Help
Search
Functional JavaScript : introducing functional programming with Underscore.js
Fogus M., O’Reilly Media, Inc., Sebastopol, CA, 2013. 260 pp. Type: Book (978-1-449360-72-6)
Date Reviewed: Aug 22 2013

Functional programming is a familiar paradigm for computer scientists. Although functional languages have existed since the late 1950s, they have never gained the popularity of mainstream languages and have not been widely adopted. The reasons for this are many, but students often conclude that the functional paradigm is difficult to understand.

Programming in a functional style, using an existing multi-purpose language such as JavaScript, can serve as a possible “half-way house,” enabling programmers to reap many of the benefits of functional programming while shielding them from the more complex constructs included in mature, fully functional programming languages. This book explores functional programming using JavaScript together with the library Underscore (which contains functions that support the functional style of programming).

The book contains nine chapters, commencing with an introduction to the functional style of programming in chapter 1. Chapter 2 presents a general discussion of the programming styles that can be used with JavaScript, leading into a detailed explanation of first-class functions together with examples that focus on the map, reduce, and filter functions.

Chapter 3 covers variable scope and closures, topics that must be understood well if one intends to make nested and recursive function calls. This is appropriately followed in chapter 4 by an introduction to higher-order functions, which take functions as arguments and return functions as results, and in chapter 5 by the composition of functions, including partial composition (“currying”). Recursion is the focus of chapter 6, with a discussion of types of recursion strategies, such as tail recursion and mutual recursion.

Up to this point, the author has concentrated on the basic components of a functional program. Chapter 7 highlights the properties that entities should ideally possess: data immutability and functional purity. While these properties are necessarily guaranteed in a functional language, care must be taken in JavaScript to ensure that the imperative nature of that language does not accidentally violate these properties.

Chapter 8 considers pipelining strategies and compares method chaining in JavaScript to data flow in functional programming. Finally, chapter 9 discusses how class-like containers can be programmed in JavaScript and explains how object-oriented thinking may be helpful in constructing pipelines.

There are two appendices. The first describes and compares the various functional libraries available for JavaScript that can be used instead of Underscore, and the second is an annotated bibliography. A comprehensive index concludes the book, and the full source code for the examples in the book can be downloaded from a dedicated website. A web page has also been set up that allows the examples to be copied and pasted into a window to be executed.

Familiarity with the technologies supporting web pages is assumed, including a basic knowledge of JavaScript. The material, including the code fragments, is clear and accurate, and is generally very well written. Although the style is a bit chatty, the author is an excellent communicator. However, I still found this book quite difficult to read, and this is in part due to the nature of the material.

The preface suggests that the book is targeted at “long-time JavaScript programmers hoping to learn about functional programming,” and “long-time functional programmers looking to learn JavaScript.” I am not convinced that either of these communities is well served. In the former case, the collection of functional examples is perhaps not large enough to explain to a novice functional programmer what the paradigm really means. In the latter case, there is already a prerequisite of basic JavaScript competence.

The bigger question is why a programmer should use a functional style when programming in JavaScript, and I felt this was not adequately answered. The benefits of functional programming are clearly articulated, but an experienced programmer would be likely to choose a mature functional language, such as Haskell, which offers benefits such as strong typing and a rich library of modules.

The strength of this book is that it shows clearly the relationship between the functional paradigm and the JavaScript language, and demonstrates how to apply the functional style to JavaScript. The examples suggest the types of activities that might usefully be performed in a functional style. For the reader who already has at least some familiarity with both JavaScript and with functional programming, this book is inspirational. For the skilled programmer, the book highlights the oddities and imperfections of JavaScript and demonstrates how these can be overcome to allow the adoption of a clean programming style.

More reviews about this item: Amazon, GoodReads

Reviewer:  Mike Joy Review #: CR141493 (1311-0952)
Bookmark and Share
 
Applicative (Functional) Programming (D.1.1 )
 
 
Javascript (D.3.2 ... )
 
Would you recommend this review?
yes
no
Other reviews under "Applicative (Functional) Programming": Date
Functional programming with Hope
Bailey R., Ellis Horwood, Upper Saddle River, NJ, 1990. Type: Book (9780133382372)
May 1 1992
Prospects for functional programming in software engineering
Banâtre J., Jones S., Le Métayer D. (ed), Springer-Verlag New York, Inc., New York, NY, 1991. Type: Book (9780387538525)
Aug 1 1992
An introduction to functional programming
Bird R. (ed), Wadler P., Prentice Hall International (UK) Ltd., Hertfordshire, UK, 1988. Type: Book (9780134841892)
May 1 1992
more...

E-Mail This Printer-Friendly
Send Your Comments
Contact Us
Reproduction in whole or in part without permission is prohibited.   Copyright 1999-2024 ThinkLoud®
Terms of Use
| Privacy Policy