Functional Design (Addison-Wesley)

Author: Robert C. Martin
Publisher: Addison-Wesley
Date: September 2023
Pages: 384
ISBN: 978-0138176396
Print: 0138176396
Kindle: B0CGHQKGYG
Audience: General
Rating: 4.5
Reviewer: Kay Ewbank

This book sets out to explain the principles, patterns and practices of functional design, and why functional programming is a good thing.

The author, Bob Martin, is well known as one of the authors and signatories to the agile manifesto. In this book, he bases his examples on Clojure because it's a simple enough language not to get in the way of learning functional programming.

Banner

The first section of the book is titled Functional Basics, and Martin starts by setting out his definition that functional programming is more than just programming using functions, it is programming without assignment statements and without variables. Chapter one defines immutability, and looks at the problem with assignments, arguing that assignment leads to temporal couplings and race conditions. 

 

Next, Martin looks at persistent data, and how working with data can mean having to "cheat" in functional terms and use variables. Chapter three adds in the concepts of recursion and iteration, which are used by functional programming to eliminate the need for assignment.

Laziness is the topic of the next chapter, starting with the idea of lazy lists which Martin defines as iterators masquerading as lists. 

This opening part of the book ends with a chapter on statefulness, with sections explaining why mutation is essential, and how life is hard but software is harder.

The second part of the book is titled Comparative Analysis, and it explorers and examines the differences between code written for a series of exercises in object-oriented and functional styles. Each chapter has a Java version and a Clojure version, and a comparative analysis. The chapters look at finding prime factors, a bowling game, and 'gossiping bus drivers' where given a number of bus drivers each with their own set of knowledge and circular route share gossip when their routes overlap. The question is, how many steps before all the gossip is shared.

This section of the book ends with chapters looking at the payroll problem, and at adding type checking to the Clojure solution for payroll.

The next part of the book consists of two chapters considering functional design, specifically how it relates to data flow and to SOLID, a set of object-oriented design concepts set out by Martin - Single Responsibility Principle, Open-Closed Principle, Liskov Substitution Principle, Interface Segregation Principle, and Dependency Inversion Principle.

The chapter on data flow contrasts object-oriented's data management with that of functional, arguing that functional code is like plumbing in the way it moves data through the process.

A section titled Functional Pragmatics comes next, with chapters looking at how to incorporate testing into functional code; how to write code that seems outside the parameters of what functional code can achieve (using the example of a simple GUI interface); and how to deal with concurrency.

Next comes a chapter on design patterns that look at tasks where functional programs might get bogged down, and ways round them. The book ends with a case study of creating a large functional program.

Overall, I found this book explained the concepts of functional programming, its strengths and drawbacks very clearly. At the end I felt I had a much firmer grasp of functional programming. Recommended.

To be informed about new articles on I Programmer, sign up for our weekly newsletter, subscribe to the RSS feed and follow us on Twitter, Facebook or Linkedin.

Banner


Racket Programming the Fun Way

Author: James W. Stelly
Publisher: No Starch Press
Date: January 2021
Pages: 360
ISBN: 978-1718500822
Print: 1718500823
Kindle: B085BW4J16
Audience: Developers interested in Racket
Rating: 4
Reviewer: Mike James
If you have ever wanted to Lisp then try Racket.



Understanding Software Dynamics (Addison-Wesley)

Author: Richard L. Sites
Publisher: Addison-Wesley
Pages: 464
ISBN: 978-0137589739
Print: 0137589735
Kindle: B09H5JB5HC
Audience: Every developers
Rating: 5
Reviewer: Kay Ewbank

This book looks at the different reasons why software runs too slowly, and what developers can do about it, starting by looki [ ... ]


More Reviews