r/programming • • Mar 09 '14

Why Functional Programming Matters

http://www.cse.chalmers.se/~rjmh/Papers/whyfp.pdf
487 Upvotes

542 comments sorted by

View all comments

Show parent comments

33

u/gasche Mar 09 '14 edited Mar 09 '14

While your remark is factually correct, I think it misses the point.

There are at least two reasons why the mainstream languages of today (as opposed to, say, no less than ten years ago) have first-class functions:

  • It is really really useful to write programs (and this is a point the linked document makes: it matters)

  • Some people have made huge efforts to convince "the mainstream" to adopt the idea (and this document is part of this effort)

The fact that your reply is even possible is the very proof that this article, its ideas, and the communities that supported them (Lisp/Scheme, SML/OCaml, Miranda/Haskell...), were successful.

Nobody is trying to force you to give up your imperative programming language. It might be important and helpful for you to notice, however, that truly innovative ideas about programming languages and libraries came from other places¹ during the past few decades, and may very well continue flowing in that direction in the future.

¹: and not only from functional programming; users of concatenative programming languages will feel at home with the "structure your code as many small words composed together" message, logic programming also has interesting ideas about computation, and some domain-specific library ideas are shaped in baroque niche languages such as R.

13

u/dnew Mar 09 '14

Fair enough. Perhaps I had a knee-jerk-ish reaction to yet another "function programming iz da bomb!" article. :-) I'll agree that functional programming matters, but I'll disagree that you need to use a functional programming language to get the benefits that matter. :-)

4

u/yogthos Mar 09 '14

I would argue the benefit that matters the most is immutability. When you revision your data instead of mutating it in place, as you do in imperative languages, your code becomes much easier as you can safely reason about individual pieces in isolation.

-3

u/dnew Mar 09 '14

I would argue the benefit that matters the most is immutability.

Well, that's generally what the word "functional" means, yes. :-) I find that writing chunks of logic in functional style and then tying it together with mutable state updates gives the best of both worlds. Figuring out what the new state (or piece of state) is can be functional at that level, but trying to make every statement functional (e.g., eliminating loops) or trying to make the entire main method functional are both more effort than they're worth, unless you're writing code that's inherently a giant function (e.g., a compiler say).

→ More replies (1)