Because functional programming is like algebra, there are no null values or exceptions. But of course you can still have exceptions when you try to access servers that are down or files that are missing, so what can you do? This lesson demonstrates the techniques of functional error handling in Scala.
Summary: Simple functional programming techniques in Scala make certain OOP design patterns, such as the Strategy Pattern, obsolete.
The OOP Strategy Pattern
Wikipedia describes the Strategy Pattern with this UML diagram:
I see some crazy/weird critics in the world. I’ll skip the details, but yes, Functional Programming, Simplified is for beginners who are new to functional programming (FP). I wrote it because I thought many other current FP books were too hard to read, and I wasted a lot of my own time with those poorly-written resources. (Frankly, when I see that something is poorly written it makes me think that the author either doesn’t care about his readers, or doesn’t understand the subject well enough to explain it well.)
I guess I could have named my book Functional Programming in Scala for Beginners, but the key thing for me is that if you want more people to learn FP — which should be a positive thing — you need to break it down into smaller components, as I have done. The book isn’t perfect, and I hope the next edition is better, but it seems to be helping a lot of people, so I’m happy about that.
As I wrote in Functional Programming, Simplified, functional programming can lead to happiness (and sanity). The quotes in this slide from Rúnar Bjarnason’s FP talk expand on what I wrote in my book. They keys are that pure functions are very simple, and you don’t have to constantly worry about the mutable state in your application.
For Cyber Monday I reduced the price of the PDF version of “Functional Programming, Simplified” to $22.50. (Price good on November 25 and 26, 2018 only.) Click here to buy the book!
Microsoft has a nice interview with FP researcher and Haskell co-creator Simon Peyton Jones.
To make the online reading a little easier, I’ve put a free preview version of Functional Programming, Simplified on fpsimplified.com. That website contains ~40 lessons from the book. For more complete previews, see my original Functional Programming, Simplified page.
I thought about writing a “functional programming in Kotlin” book, but I think that Kotlin and Scala are similar enough that Functional Programming, Simplified will be good for Kotlin programmers as well as Scala programmers.
I’m surprised when many functional programmers feel the need to say something bad about Scala. As a community, that makes them seem like a bunch of people who aren’t very nice. There are things I don’t like about Haskell, F#, Lisp, Scala, Kotlin, Go, Perl, PHP, Python, C, C++, etc., but I don’t feel the need to take pot shots at any languages or individuals.