Scala and functional programming. Two aggressively-polarising software development topics jointly-explicated in this short book.
Actually it's not really a book. And while only 300 pages short, it takes months to complete. That's because Functional Programming in Scala is a deep-dive into the world of functional programming, bursting with hands-on exercises that must be completed to get any real benefit. Ergo, it's a training manual for functional thinking.
To me this book was a journey. I went into the tunnel hoping to be comfortable with functional programming concepts. And I also hoped to learn some advanced Scala tricks. Satisfyingly, I emerged from the tunnel with both check-boxes firmly ticked.
I'm not suddenly a functional programming expert. Nor do I now think that functional programming is the one true way. But I feel massively empowered by the knowledge and skills I have gained from my investment in Functional Programming in Scala. If you use Scala, you probably should read this book. If you use other languages, but love learning, it's well worth it for you, too. Whatever your background, though, you will definitely need to put in a lot of effort.
Forget that OOP Stuff
From the kick-off this book presents you with topics that contradict conventional object-oriented programming. Compromising encapsulation for referential transparency, pre-emptively generalising functions, and shockingly - supertypes inextricably coupled to their subtypes. But if you like your assumptions being challenged, you'll love all of it.
The latter case - known as algebraic data types - especially. If we don't care about polymorphism. And if we know that there are only a fixed set of implementations. Why can't the supertype be coupled to its children?
In fact, with algebraic data types, we can enforce correctness through the compiler. In combination with pattern matching, the compiler will tell us if we haven't handled one of the specific implementations (cases). We can make the type system do more work.
Functional programming makes heavy use of algebraic data types. And once you learn about them you will love them, as you will other functional concepts.
Lots of Head Scratching
After the first few chapters, some of the concepts in this book I found mesmerisingly hard. Getting my head into the pattern of seeing functional programming as describing programs rather than executing them took a while. But understanding this in the context of lazily-evaluated streams took me ages.
Even when I finally conquered that mountain, many more appeared. Admittedly I had to accept defeat on some concepts. I'd estimate I only did about 70% of the exercises, too. But the seeds have been planted - by re-reading this book or pairing with FP experts, I'm confident those concepts will make sense eventually thanks to what I did manage to learn.
Surprisingly, the chapter on Monads was one of the easiest to follow. Undoubtedly, this book contains the best explanation of monads I've encountered. I haven't mastered monads, but I can explain them, I can spot them, and I can write them.
Academic, Arrogant... a Little Bit
Born from mathematics with its underpinning of proofs and algebra, functional programming is almost academic by necessity. And this book certainly contains proofs and equations. Honestly, but not a huge amount. Certainly nothing to put you off if maths isn't your strong point. But you will need to make an effort.
Personally, I felt the authors, at times, were a bit biased and arrogant in favour of functional programming and abstract academic thinking. Reassuringly, they don't dictate how you should code, and nor do they blast holes in object-oriented programming with rebellious bitterness on every other page, though.
Lots of Questions
Overall I'm not sure functional programming is exclusively better than OOP. Undoubtedly it has a lot to offer. But some of the extremes you have to go to in avoiding mutable state are extremely questionable.
In addition, the relentless focus on finding generalisations and common abstractions seems like a dangerous attitude that leads to a greater focus being placed on technical perfection as opposed to solving real business problems. For example, all of the demonstrations in this book focus on library code like parallel programming libraries or testing libraries. There is almost no discussion of how you would write line of business apps or domain models functionally.
What I'm alluding to here is the fact that, this book has got me into the world of functional programming. I have lots of questions and uknowns that I now need to find answers for. And that summarises the effect of this book nicely - it will set you on your path to functional programming wizardy, but it's one small step of an epic journey.