Follow the Author
Functional Programming, Simplified: (Scala Edition)
Enhance your purchase
Sale! This book is currently on sale! The normal price is $34.99.
If you’ve had trouble trying to learn Functional Programming (FP), you’re not alone. In this best-selling, highly-rated book, Alvin Alexander — author of the Scala Cookbook for O’Reilly, the Scala Book for the official Scala website, and former teacher of Java and Object-Oriented Programming (OOP) classes — writes about his own problems in trying to understand FP, and how he finally conquered it (and you can too!).
In this book he teaches FP in a simple style, without worrying about abstract concepts like functors, monads, and category theory. Instead, he explains FP through a series of small, pragmatic lessons and examples.
For instance, the first thing he learned is that experienced FP developers (FPers) are driven by two goals: to use only immutable values and write only pure functions. But then later he learned the REAL truth: FPers have these goals because their true desire — or mental model — is that they want all of their code to look and work just like algebra.
While that sounds simple, it turns out that these goals require them to use some advanced Scala features — which they often use all at the same time. As a result, their code can look completely foreign to novice FP developers. As Mr. Alexander writes, “When you first see their code it’s easy to ask, ‘Why would you write code like this?’”
But then Mr. Alexander answers that “Why?” question by explaining the benefits of writing pure functional code. Once you understand those benefits — your motivation for learning FP — he shares five rules for programming in the book:
- All fields must be immutable (‘val’ fields).
- All functions must be pure functions.
- Null values are not allowed.
- Whenever you use an ‘if’ you must also use an ‘else’.
- You won’t create OOP classes that encapsulate data and behavior; instead you’ll design data structures using Scala ‘case’ classes, and write pure functions that operate on those data structures.
In the book you’ll see how those five, simple rules naturally lead you to write pure, functional code that reads like algebra. He also shares one more Golden Rule for learning:
- Always ask “Why”?
Lessons in the book include:
- How and why to write only pure functions
- Why pure function signatures are much more important than OOP method signatures
- Why recursion is a natural tool for functional programming, and how to write recursive algorithms
- Because the Scala ‘for’ expression is so important to FP, dozens of pages explain the details of how it works
- In the end you’ll see that monads aren’t that difficult because they’re a natural extension of the Five Rules
- The book finishes with lessons on FP data modeling, and two main approaches for organizing your pure functions
As Mr. Alexander writes, “In this book I take the time to explain all of the concepts that are used to write FP code in Scala. As I learned from my own experience, once you understand the Five Rules and the small concepts, you can understand Scala/FP.”
Please note that because of the limits on how large a printed book can be, the paperback version does not include all of the chapters that are in the Kindle eBook. The following lessons are not in the paperback version:
- Grandma’s Cookies (a story about pure functions)
- The ScalaCheck lessons
- The Type Classes lessons
- The appendices
Because those lessons didn’t fit in the print version, they have been made freely available online.
About the Author
- Publisher : CreateSpace Independent Publishing Platform (December 7, 2017)
- Language : English
- Paperback : 728 pages
- ISBN-10 : 1979788782
- ISBN-13 : 978-1979788786
- Item Weight : 2.94 pounds
- Dimensions : 7 x 1.64 x 10 inches
- Best Sellers Rank: #661,209 in Books (See Top 100 in Books)
- Customer Reviews:
About the author
Reviewed in the United States on April 1, 2019
Reviews with images
Top reviews from the United States
There was a problem filtering reviews right now. Please try again later.
Thanks to this book, I'm starting to believe that the right boundary between services and data pipelines is somewhere between object-oriented and functional programming paradigms. Those paradigms are another set of trade-off's for software and data engineers engineer to have in their tool-kits.
Functional programming is like guardrails for code in distributed computing environments. Simple and extremely powerful when basic rules are followed. Because math.
The book doesn't cover much about Spark-specific topics, and yet was still hugely beneficial for me because I realized that a DataFrame is just another data type. FP concepts can be applied to a DataFrame in the same way they apply to a string, int, list, map, or any other data type.
While there a more technical introductions to FP such as Functional Programming in Scala, I had tried it and found it hard going. The exercises in particular went a bit beyond simply illustrating the concepts, and were just plain hard.
This book on the other hand has a lot more conversational approach to FP. The author explain the concepts one by one, building on top of precedent lessons. He also talks about how he feels about each concept, what new ability it gives us, when it is good to use, etc.
I often see Functional Programming in Scala as a book that gets recommended to aspiring functional programmers and that suggestion is very misguided. Functional Programming in Scala is terrific once you've been doing FP for a few months to a year.
Functional Programming is daunting and hard to learn: Functional Programming Simplified makes that easier. It is the book to get you started on FP.
Wish I could rate it more highly.
Overall the book is well-written and approachable. It covers everything you could want to know about functional programming, and every chapter has several links to more books and sources in case you want to dig even deeper.
Top reviews from other countries
On the other hand, Alvin Alexander's writing is clear and easy to read, and despite not being a newbie, I learnt a few new things, so perhaps my difficulties with this book were that I'm not the target audience.
With that being said, not saying the book is useless, i found it presents some good arguments in the pros and cons of FP and the Monad concept is well explained (slowly), what I complain is the pages of the book could easily cut down to half without losing anything.
I'd certainly recommend this to any developer who wants to learn functional programming.
There are large sections which are useful to read but beware this is quite a rambling account of fp not useful to anyone with any non-trivial experience of Scala.
Coming from no prior functional programming experience apart from bits of internal iterations with lambdas and predicates in Java 8 I must admit... wow. What a book. Two weeks passed since I got it, I am on page 200 already (sic!) and enjoy every smallest bit of it. Alvin Alexander did an INCREDIBLE job of a really thorough introduction, he told the readers not to be afraid of FP jargon, he first explains an idea without telling you what it is, introduces you to a common pattern to then tell you... "it wasnt too bad too follow right? oh btw, in FP jargon we call this X". Every 10 pages I feel another lightbulb goes on in my understanding on functional programming.
Too bad I can't grade higher than 5 stars. My company uses FP extensively and coming from procedural, OO programming I have to learn it too. Definitely I will be speaking to the company to buy a few copies to add to their library. An absolute must-read for anyone who wants to understand FP.