Book Review: Functional Programming in Scala

Wed, Dec 03 2014

I can’t remember who but someone stated that if a technical book does not make your head spin, then there is no point in spending your time reading it. For me, “Functional Programming in Scala” certainly did this.

The book is published by Manning and its final version was released in August 2014. At the Vienna Scala User Group we formed a study group and started to work through this book together back in February. We were able to obtain a relatively finished version through the Manning Early Access Program (MEAP). Since then we have been meeting regularly to discuss its content and are now on the final chapter.

On the first page the authors, Paul Chiusano and Rúnar Bjarnason, state:

We begin this book with a radical premise—that we will restrict ourselves to constructing programs using only pure functions with no side effects such as reading from files or mutating memory. This idea, of functional programming, leads to a very different way of writing programs than you may be used to.

They were not lying. While I was familiar with some of the topics, mainly through the Coursera course Functional Programming Principles in Scala, this book goes far beyond the course, and will most likely be an interesting challenge for anyone not familiar with this style of programming.

The book is split into four parts: Part 1 starts out with six chapters to explain the basic principles such as functional data structures, handling errors without exceptions, strictness, laziness, and purely functional state.

What I really like about this book is the approach to teaching that it takes. Instead of explaining the core abstractions such as monoids, monads, and applicative functors straight away, advanced problems (namely parallel processing, property-based testing, and parser combinators) are tackled first in a purely functional way. During the course of those chapters certain patterns, laws, and combinators are encountered over and over again which are only then tied together in the next part with the introduction of said abstractions.

The fourth and final part talks about how to handle effects such as I/O and mutation.

Functional programming is a complete programming paradigm. All programs that we can imagine can be expressed functionally, including those that mutate data in place and interact with the external world by writing to files or reading from databases.

The authors state multiple times that their goal is not to teach how to implement the presented problems in a purely functional way but how to approach such a design. While this book won’t make you an expert in functional programming straight away, it will put you well on your way.

Be aware that this is not a casual read and studying the material thoroughly will consume a lot of time. Throughout the 15 chapters there are over 200 exercises and nearly all require writing code. To get the most value out of this book, I highly recommend trying to tackle all of them.

Also, don’t read this book if your primary goal is to learn Scala. It’s a book about functional programming and only uses Scala as the vehicle to explain the concepts. It can be read by any developer since the basic syntax of the language is introduced as needed. For learning Scala I’d recommend either Programming in Scala by Martin Odersky, the creator of the language, or Scala for the Impatient.

“Functional Programming in Scala” is a fantastic book, there is really nothing negative I could say about it. I have learned a great amount from it and recommend it to anyone interested in functional programming.

You can buy it from your favorite book retailer or directly from its publisher Manning.

comments powered by Disqus