User loginNavigation |
What are the real benefits of FP?I have much more experience with imperative code (like most programmers) but I'm starting to branch out and have done a little bit of Ocaml and am endeavouring to learn lisp. So I stumbled on this article, "Functional Programming For The Rest of Us," thinking it might inform me about the benefits of my choice to learn some functional languages. My question is: What am I missing? The article seems to ascribe a number of features to functional languages that don't seem to be particular to them. Treating functions as first class objects for instance. Or partial evaluation. He says that debugging is much easier because there's no global state -- but you can just view global variables as syntactic sugar for variables that are passed to every function. He claims that patching Java code at runtime would be much harder than in FP -- but I don't see how that's something inherent about Java as a language (as opposed to implementation). He says this is because in an FP language "all state is stored on the stack." Which a nice thing to stay, but I could just as easily say, in a C program, "all state is stored in the global segment, the code segment, the data segment, and the stack segment." So if saving and modifying the stack is so easy, why can't I do it for a C program? Apparently we have some method for restoring the stack segment, the code and data segments are constant, and the global segment is just a list of values. Closures are also described as being a functional language thing. I see them as a "easier to implement if you're delaying compilation until runtime" sort of thing. Python 2.5 can supports all the coding techniques described in the article and it certainly feels more imperative than functional, and certainly lacks the most distinguishing feature of FP I know of (no side effects). Is he just confusing functional languages implementing certain features before imperative languages did with there being an inherent advantage to functional languages? Admittedly, one advantage that he does bring up that seems accurate to me is that functional languages are easier to mathematically reason about. Although I remain skeptical of the practical advantages of this -- for all the cheering about it, every functional language implementation I've seen has been slow compared to C (yes I know it hard to objectively state that one language is faster than another, but one somehow becomes remarkably better at determining this when there's a paying client that needs something super performant). If lack of side effects and lazy evaluations provide such an optimization bonanza, why haven't I seen it yet? By dataangel at 2006-06-21 04:41 | LtU Forum | previous forum topic | next forum topic | other blogs | 26576 reads
|
Browse archives
Active forum topics |
Recent comments
21 weeks 17 hours ago
21 weeks 21 hours ago
21 weeks 21 hours ago
43 weeks 2 days ago
47 weeks 4 days ago
49 weeks 1 day ago
49 weeks 1 day ago
51 weeks 6 days ago
1 year 4 weeks ago
1 year 4 weeks ago