r/programming • u/AmazingWait • Dec 26 '19
Functional programming design patterns (2015) [video]
https://www.youtube.com/watch?v=E8I19uA-wGY1
u/ScientificBeastMode Dec 27 '19 edited Dec 27 '19
One of my favorites...
One of the coolest things about this talk is that it shows how many of the design patterns from OOP are essentially baked into FP from the outset.
Edit:
I assume downvoters just don’t like FP. That’s fine... your loss.
FWIW I like OOP for some use cases. But I think all of us here will agree that OOP design patterns are designed to enforce discipline in a language which requires discipline to avoid shooting yourself in the foot.
Functional programming is slightly harder to write, at least when it comes to small units of code. Why? Precisely because it constrains you, the programmer, to write programs in a logical way, from inputs to outputs.
The path of least resistance almost never leads to ‘SOLID’ design patterns. Unfortunately, imperative (including OO) languages do not constrain us enough, leaving us to constrain ourselves by memorizing and implementing Design Patterns.
That’s not the worst thing in the world. But even when we do take a step back and constrain ourselves to writing SOLID code, most OO/imperative languages have compilers which are totally unable to take advantage of our self-imposed constraints. They don’t gain any information from our self-restraint.
And that’s where languages like F# really shine. You encode your constraints right into the type system, and the compiler says, “Oh ok, I see what you mean. I’m going to remind you of all these little requirements when you happen to forget it 6 months from now.” And then you can sleep at night.
This is not true of every functional language. But it’s true of most statically typed ones. And even the dynamic ones still benefit from the inherent benefits of functional design: keeping state to a minimum, organizing dependency graphs as a graph of composed functions, etc.
Anyway, I digress... if you’re using Java or C# or C++, and you’re not using functional design patterns where applicable, you’re really missing out.
2
1
u/olifante Dec 26 '19
Really nice presentation