4 ms·
>functional messes are an order-of-magnitude worse than imperative/OO ones Why so?
by pydry 6y ago
>functional messes are an order-of-magnitude worse than imperative/OO ones
Why so?
- DanielBMarkham 6y agoSymbol/Semantic leakage. In imperative/OO, I'm organizing as I go using well-established and understood paradigms. In functional programming, you're making these paradigms as you go along, or at least you should be. If you come in with an "I'm going to kick some ass by making these classes to solve my problem" attitude, you're already headed down the OO track whether you realize it or not. Then, sure as night follows day, you or somebody else starts using a functional paradigm, say HoF. There's nothing wrong with any of that. As a professional, you want to be good in multiple paradigms. The problem is that you're mixing them all up, whether you realize it or not (Most of the time, programmers don't realize it) And now, every piece of code can go down two entirely separate tracks as you suss out your architecture. Not only is that not going to work, it's going to make debugging and maintenance a nightmare. This is very, very similar to how good C++ shops work. You've got to tightly limit the way you solve problems in order for all of the programmers involved to be to reason about the code.
- sbelskie 6y agoHow are these points specific to OO vs. FP, instead of just paradigm I know vs. paradigm I don’t? F# code, from my somewhat limited experience, seems to almost always be organized logically (top to bottom, types separated from functions) using well-established patterns. Obviously if you decide to write a bunch of classes and mutating code in F# when more idiomatic approaches would work, it’s going to get hairy. I feel like I’m missing your point.
- DanielBMarkham 6y agoHappy to talk about it. Ping me. I've already been misunderstood a couple of times in this thread and I fear it's not going to get any better. After all, this is really more of a conversation than a point-counterpoint situation.
- KurtMueller 6y agoThere are plenty of well-known functional language paradigms that have been discussed (and satirized) for decades.
- thomasz 6y agoIMHO it's tooling. The industry has spend decades to help you to deal with the kind of mess OO tends to produce. The tooling isn't anywhere close when you have to deal with a mess of functions returning functions that return functions.
- samus 6y ago> a mess of functions returning functions that return functions. That is just a curried function with three arguments. The bigger problem is that programmers still have to understand how Hindley-Milner type inference works to figure out type errors. This gets worse when you add in type classes, dependent types and (Yog-Sothoth help you) lenses. Your point is still true. For any language, it is important to have an IDE ecosystem in place. The tooling must enable developers to move beyond fighting the unruly or boring parts of the language and instead leverage it to work on the domain.
- thomasz 6y agoNo, not necessarily. Curried functions have their own problems because they are missing the vital parameter names. But that's not what I meant. Think of the classic memoization example (written without a compiler at hand...) let createMemoizer f = let cache = Dictionary<_,_>() let f' = fun x -> match cache.TryGetValue(x) with | (true,value) -> value | (false, _) -> let result = f x do cache.[x] <- result result f' The signature is ```createMemoizer (f:'a->'b) -> 'a->'b```, which is not very telling, especially if it is returned by yet another function, so that even the createMemoizer name is lost. In classic OO, I'd just get a Memoizer object that carries vital documenation and what not with itself, as it is passed around. It's no even that much longer, it's just not as elegant to use. class Memoizer<TINPUT,TOUTPUT> { Dictionary<T,TOUTPUT> cache = new Dictionary<T,TOUTPUT>(); Func<TINPUT,TOUTPUT> f; /* ... */ public TOUTPUT Invoke(TINPUT parameter) { if (!cache.TryGetValue(parameter, out var result)) { result = f(parameter); cache[parameter] = result; } return result; } }
- deleted 6y ago[deleted]