by Michael Bevilacqua-Linn
Functional programming is a style that is wildly popular in academia, but substantially absent in business programming. Part of the reason for this situration is that, to migrate to the functional way of thinking, you need to relearn many fundamental techniques from simple looping, to handling collections, even how you think about simple problems. Most experienced developers just don't have the bandwidth to relearn their craft from top to bottom for the small and, at times, hypothetical lift that functional programming will provide. As a result, they most often admire it at a distance and continue working with the familiar imperative and OO styles they know.
The author of this work contends that on the JVM, at least, there are plenty of opportunities to improve OO code by selective integration of functional techniques. (This is an approach implicit in the multi-paradigm model embraced by Scala.) The points he focuses on are traditional design patterns; and he suggests ways of replacing them in existing code with functional substitutes. The benefit is less code, better code quality, and a greater amenability to parallel execution.
As a working example, he writes a micro Web framework in Java that uses MVC. He then rewrites it in Scala and Clojure. From there, he devotes a chapter each to rewriting the patterns found in the exercise using a functional approach. These patterns include the command pattern, builders, iterators, the template method, null object pattern, and the strategy, decorator, and visitor patterns.
He then elaborates functional patterns for thoughtful addition to existing OO programs: tail recursion, filter-map-reduce, chain of operations, memoization, and others.
The result is an excellent and deep exploration of programming concepts. Functional Programming Patterns in Scala and Clojure is hard-going because of the density of the material and the amount of knowledge the author expects from the reader. But for developers who know their patterns, have thought carefully about program design, and can work through the Scala examples (which are close enough to Java and C++ to be followed satisfactorily), this book is likely to change the way they write code significantly for the better. Highly recommended.