How Do I Learn Some Functional Programming?
I am sure you have heard about functional programming already. Otherwise, you would never find this article :)
If you are still unsure what is it all about, I’d propose you to stop reading this article and switch to Uncle Bob’s article Functional Programming Basics.
You know what, just go and read it anyway!
The first step is the most controversial. Yet, I personally think it is the most useful one anyway.
Grab Practical Object-Oriented Design in Ruby (POODR) by Sandi Metz and read it.
Yes, you read it correctly: Object-Oriented Design.
“Why?! How… How does it relate to Functional Programming?!” you may wonder.
The thing is — you really need to experience a good, nice OOD to see the immediate value of Functional Programming and make the transition from OOP to FP smooth and easy.
Ah, and do not be afraid of Ruby. The examples are nice and easy, you will understand everything, I promise!
And yes, we have some goodies. But I won’t show you everything right away so that you do not get overwhelmed.
I would suggest you the thing I keep repeating all the time:
Start writing some code right from the beginning!
I think this is the most pragmatic book you can find to actually start writing some functional code in JS. That’s it!
You will learn how to use
underscore library (or
lodash, if you will) right away.
It will lead you through applicative programming and some basic combinators, showing how it differs from the OOP and Class-oriented approaches you get used to.
Ah, such a nice journey!
Ok, you have played with
lodash already, and all of those
.pluck are not scary and useless anymore?
Watch this then: Hey Underscore, You’re Doing It Wrong!.
Brian Lonsdorf will show you the idea behind tacit programming technique.
You may find it quite similar to unix tools philosophy of putting the arguments in a specific order: from less often changed to most often changed, target object last, like in
git checkout branch. See the similarity?
This is not the coincidence! This style pushes composability further.
What’s the next step?
You will learn some SKI combinator calculus and high-caliber combinators and decorators with a nice and pleasant ES6 syntax.
Also, you will learn about all those mixins and delegation based on prototypes in JS. It will make you a better programmer already!
Ok, now you have tried some low-hanging fruits and maybe get a habit of simplifying things.
It’s time to tread on a more abstract ground and learn some Theory™!
It will lead you through the path of Real-Deal Functional Programming: currying, Hindley-Milner type system, functors, applicatives, monads… Oh, my!
From now on, the World will never be the same again for you!
I think, this is the time you can start using elm and fully appreciate all the powers it gives you.
But, if you want to proceed the journey from here, I would suggest you fighting the real dragon: Functional Programming in Scala
by Paul Chiusano and Rúnar Bjarnason.
They say it is one of the best books on FP today.The Real Deal™. Not the toys.
Not only will you learn other flavours of Functional Programming, but also you will experience a type of books you have never seen before!
And this is the time where I will leave you on your own.
After spending the time with all those FP, you are a completely new programmer right now!
I would love to hear back from you!
- Have you conquered the quirks of Category Theory?
- Have you mastered the DataFlow programming? Or maybe Algebraic Effects? Or even Dependent Types?
Originally published at metadevelopment.io blog on June 18, 2016.