Everyone’s crazy about FP
I read this in Mark Seemann’s blog:
Most of the classic design patterns are based upon the idea of programming to an interface instead of a concrete class. In OOD, it’s necessary to point this out as a piece of explicit advice because the default in OOD is to program against a concrete class.
That’s not the case in FP because functions can be composed as long as their signatures are compatible. Loose coupling is, so to speak, baked into the paradigm.
This is nonsense. The fact that functions can be composed as long as their signatures are compatible does not imply that the functions you compose are loosely coupled. In FP you can easily write functions that depend on the concrete way that information is represented. Changes in how a function returns data may break other functions down the road. I would say that in fact the opposite is true: the main danger of FP is that concrete representations are passed around all the time. At least this much can be said about OO, that OO pushes towards encapsulation of data representations. This is “baked into” the OO paradigm.
Look, I fully agree that FP is great. But how much of this new enthusiasm for FP is due to FP being a new thing (at least to these new converts?) People trying FP now did not have the time to write spectacularly bad systems with FP. Yet. Then what? We’ll be praising Logic Programming over FP? Me, I’d rather spend my time learning to use one paradigm *well*.
May 26th, 2012 at 11:21
Indeed primitive obsession in functional languages is still one of the real difficulties for me to overcome while learning FP.
It’s also possible that languages like Clojure make the same trade-off between paradigm and familiarity that C++ and Java made with OO; in both cases what we’re seeing is a dumbed-down version of the real OO/FP thing, either classes full of setters or programs with no referential transparency.
May 26th, 2012 at 15:38
As far as I know, Clojure is a fine language. It’s a very credible variant of Lisp, which is certainly not a dumbed down version of anything, and I hear it has a very good JVM implementation.
What I object to is the implied statement that “Clojure (or FP) is great because OOP has problems”. FP is a great thing on its own merits, thank you! And OO is a great thing too. Being good at OOP takes care, practice and perseverance. So does being good at FP!
Don’t blame the tools when your results are not good.
June 14th, 2012 at 04:56
it is a common misconception that dynamically typed language remove the types dependencies.
it is true only for the edit and compile/interpretation time, while there is still a dependency at run-time.
So the DIP holds true also for dynamically typed language.