4 ms·
I think that FP is a valuable addition, but not strictly better than OOP (or procedural/imperative). I think that some problems are better expressed in FP, and
by kaeluka 11y ago
I think that FP is a valuable addition, but not strictly better than OOP (or procedural/imperative). I think that some problems are better expressed in FP, and some are better expressed in an imperative manner and a language should let you choose.
edit: s/think/BELIEVE/
- pdkl95 11y agoThat conflict between OOP and FP is the "Expression Problem". Choosing which side to use for a given problem is an important part of software design. http://c2.com/cgi/wiki?ExpressionProblem http://c2.com/cgi/wiki?ExpressionProblem
- kaeluka 11y agoWhat you say is sound but, IMO, not complete. There's something more to immutability vs. mutability. They both can, for instance, describe both data bases and mathematics. But there's no doubt in my mind that mutable state is better suited for the former, and immutability for the latter. It's "stuff" vs. "knowledge" that's modelled; stuff wants to change and knowledge wants to be shared.
- pmontra 11y agoIn my experience there is another kind of expression problem. It's usually something like this "a:b:c".split(":").first # Ruby vs String.split("a:b:c", ":") |> List.first # Elixir The length of the two statements is telling. Luckily Elixir has the |> and I don't have to write List.first(String.split("a:b:c", ":")) OO is generally more convenient to read. It's also more convenient to think into, even when I was young and I looked at C and Lisp without much priming from previous experiences. Functional has other advantages. I quote Joe Armstrong on that: [with OO] "You wanted a banana but what you got was a gorilla holding the banana and the entire jungle." That wasn't much different with plain C though, which could do structs and be somewhat object oriented too if you coded in the right way. And you could end up with a jungle of functions as soon as you write enough modules that need each other.
- koloron 11y agoIMO, the difference in readability has little to do with the difference between OOP and FP. What's important is the expressiveness of the language. So Ruby can be very easy to read because you can simply keep appending methods to the right. In Haskell you can do the same, only you'll prepend functions on the left, so you end up reading expressions from right to left: (intercalate ", " . map show . Map.elems) myMap What I find really hard to read, are expressions where the direction of the data flow changes, something that often happens to me in Java: Streams.takeWhile(list.stream().map(e -> f(e)), e -> e.isNeeded())
- deadowl 11y agoThree completely unrelated things I guess. 1. Expressiveness is important? Expressiveness is why I don't like Perl. 2. You can certainly implement patterns analogous to OO in functional programming with closures and first-class functions. 3. Reading in the order of execution via chaining is definitely a lot more intuitive than reading from the inside out or right to left.