3 ms·
I am not sure what I am doing wrong, but using functional techniques improved my C# quite a lot.
by _random_ 12y ago
I am not sure what I am doing wrong, but using functional techniques improved my C# quite a lot.
- PaulAJ 12y agoIts an example of the "blub paradox": if you haven't used a pure functional language then its hard to see what the problem is. The crucial thing about pure functional languages is that they decouple the logic of the program from the order of the computation. In an imperative language control flow and data flow are explicitly interleaved, with complex dependencies between the two. In many cases a particular bit of code is only correct if another bit of code has been executed previously, and its up to the programmer to keep track of all these dependencies. In a pure functional language this coupling between data flow and control flow is broken because all the data dependencies are made explicit and visible to both the compiler and the programmer. That frees the programmer from bothering about it (and automating low level programming issues is always a Good Thing), and it also enables the compiler to optimise it. So for instance in Haskell the compiler will rewrite this expression map f (map g xs) into this map (f . g) xs The first line would iterate through the list "xs", building up an intermediate result list by applying "g" to every element. It would then iterate through this intermediate list applying "f" and building up the result. The second line iterates through the list only once, applying "g" and then "f" to each element in turn. Haskell can do this because "f" and "g" are guaranteed by the type system to have no side effects, so it doesn't matter what order they are executed in. In impure languages the order of execution matters, so the compiler can't switch things around in this way without changing the meaning of the program. The programmer also gets the benefit. If you see "x = complexThing" you can always replace "x" with "complexThing" and vice-versa anywhere that "x" is in scope, without changing the meaning of your program. That makes it much easier to reason about what your program does.
- EdwardDiego 12y ago> Its an example of the "blub paradox": if you haven't used a pure functional language then its hard to see what the problem is. The blub paradox has always been a stalking horse for condescension, IMO. I've used a purely functional language, and I don't see the problem to be that significant. I see only benefits from traditional OO languages obtaining more FP features.
- _random_ 12y agoI am disciplined enough to keep my functions pure and use immutable data structures where they are useful. I try to apply each paradigm where it makes most sense. What is a pure functional way of implementing GUIs for example to use instead of MVC/MVVM patterns?
- nmrm 12y agoThis SO post does a decent job and answering this question: http://stackoverflow.com/questions/2672791/is-functional-gui-programming-possible http://stackoverflow.com/questions/2672791/is-functional-gui... It's also worth noting that frameworks such as Java's Swing are somehow functional in their architectural style, if not in their implementation.
- PaulAJ 12y agoInstead, how about a pure functional way of doing MVC? http://www.haskellforall.com/2014/04/model-view-controller-haskell-style.html http://www.haskellforall.com/2014/04/model-view-controller-h...
- pron 12y ago> Its an example of the "blub paradox": if you haven't used a pure functional language then its hard to see what the problem is. Well, if a problem is so hard to see, maybe the solution to it is not all that important... Like I said in another comment, I certainly believe that handling shared mutable state is a problem, but I certainly don't think pure functional programming is the only solution (in fact, I don't think it's a solution at all).
- 6cxs2hd6 12y agoThere's an old saying, "perfect is the enemy of good". Here OP plays the role of Perfect. You are Good. (Opinions vary about the wisdom of this old saying. See: perfect vs. good.)