3 ms·
monads are a very simple pattern it takes 5 minutes to understand it, the jargon is complex, the implementation is not. case in point https://youtu.be/C2w45q
by peoplefromibiza 4y ago
monads are a very simple pattern
it takes 5 minutes to understand it, the jargon is complex, the implementation is not.
case in point
https://youtu.be/C2w45qRc3aU https://youtu.be/C2w45qRc3aU
objects are a very leaky abstraction that usually brings people to build taxonomies, mostly unrelated to the parent.
reuse of code, which is the selling point of OOP,also comes often short with a miriad of very specialized subclasses that have nothing in common anymore.
OOP is not horrible, but it requires a good amount of discipline to get it right, while FP has less concepts and you can (usually) silo the "and now for the tricky bits" (cit. Robert Virding) in a small core.
the rest is simple pure functions that have also the benefit of being stupid trivial to test.
Also, you don't have to be purely functional nowadays, and that helps a lot.
If only I learned FP sooner, my life as a programmer would have been so much better.
- freedomben 4y agoYou're point about testability is a good one that I feel is often missed. Trying to test functions in OOP code is often impossible because they presuppose some state in the "object" and if it's not initialized properly, it doesn't work. Then they also often make side effects. So you end up building a huge test harness to build up some state, run one test, and tear it all back down again only to rebuild it from scratch for the next test. It's doable of course, but it's easy for a simple CRUD app to have a 15 minute test suite and for tests to become flaky because of some unexpected state change done in some unrelated test on the other side of the code base. That's a special form of hell
- goostavos 4y agoMonads are indeed way simpler. Just a few beautiful laws. The problem is that they take a loooooooooooong time to really internalize. Saying it takes "5 minutes" is empty in the same way that "learn C++ in 24 hours" claims are (or you're hella smart!). There's a quote that floats around that's like "as soon as you understand monads, you lose the ability to explain monads." It takes a ton of leg work to make them click. They're simpler, but definitely not easy (in the Rich Hickey sense).
- peoplefromibiza 4y ago5 minutes is the time it takes to understand how the pattern works. Be good at it? More like a thousand hours. there is nothing that is really simple, but before being simple, everything looks difficult. p.s. I love Rich Hickey and especially his keynotes at Clojure conferences. I've watched simple made easy at least 10 times.
- bitL 4y agoOk, so you understood flatmap and therefore monads in 2 minutes. Now you need something that needs nested monads. That's where major complexity suddenly appears - your code is no longer simple and is full of artificial constructs like transformers just to do simple things. Moreover, anyone who reads your code must know all language constructs you are using or they are lost and can't fix any issue in your code.
- solomonb 4y ago> Moreover, anyone who reads your code must know all language constructs you are using or they are lost and can't fix any issue in your code. Does this not apply to every language ever?