Why hasn't functional programming taken over yet?

Tagged:
Freelance Jobs

I've read some texts about declarative/functional programming (languages), tried out Haskell as well as written one myself. From what I've seen, functional programming has several advantages over the classical imperative style:

  • Stateless programs; No side effects
  • Concurrency; Plays extremely nice with the rising multi-core technology
  • Programs are usually shorter and in some cases easier to read
  • Productivity goes up (example: Erlang)

  • Imperative programming is a very old paradigm (as far as I know) and possibly not suitable for the 21st century

Why are companies using or programs written in functional languages still so "rare"?

Why, when looking at the advantages of functional programming, are we still using imperative programming languages?

Maybe it was too early for it in 1990, but today?


pankraxH
2010-05-14 16:24:03 Scores:39
IMHO this should be community wiki.
Péter TörökH
2010-05-14 16:27:37 Scores:5
There are several language-specific answers to this question, like [this one](http://stackoverflow.com/questions/145228/what-could-make-erlang-more-popular-and-widespread) and [this one](http://stackoverflow.com/questions/68717/will-lisp-ever-become-super-popular).
Robert HarveyH
2010-05-14 16:29:35 Scores:2
@Peter: pankrax doesn't have enough rep to see the cw checkbox, and he probably doesn't know what cw means anyway. Flag for moderation and put "should be community wiki" in the description.
Robert HarveyH
2010-05-14 16:30:19 Scores:0
@Robert: You can make your questions CW at 1 rep but it is strange that the first respone I get comes from the CW police ^^
pankraxH
2010-05-14 16:32:03 Scores:1
Yay, I am a member of the mighty CW Police!!! Where do I get my super cool CW Sheriff badge? ;-)
Péter TörökH
2010-05-14 16:41:02 Scores:3
@pankrax, it is also strange (to me at least) that you, supposedly a newbie at SO, already talk about CW police... apparently some memes spread fast nowadays ;-)
Péter TörökH
2010-05-14 16:42:30 Scores:4
@Péter Török: questions should be marked community wiki when a user wants his question or answers to be publically editable by anyone. Wiki is *not* used to classify posts as subjective or "no single answer", we use tags for that purpose. @pankrax: don't feel pressured into wiki'ing your posts if you don't want to.
JulietH
2010-05-14 16:48:41 Scores:3
Hasn't this been discussed enough already? http://stackoverflow.com/questions/411290/why-do-people-think-functional-programming-will-catch-on-closed, http://stackoverflow.com/questions/36504/why-functional-languages, http://stackoverflow.com/questions/1786969/pitfalls-disadvantages-of-functional-programming, http://stackoverflow.com/questions/216160/are-we-in-a-functional-programming-fad, etc.
gnoviceH
2010-05-14 17:21:35 Scores:2
@gnovice: If this question hadn't been asked, we wouldn't have gotten Eric Lippert's thoughtful and thorough answer.
Robert HarveyH
2010-05-14 17:35:59 Scores:0
@Juliet -- if you want to debate this, please come to Meta and debate it. What you are stating as fact is not the consensus of the community. Some agree, some disagree.
bmarguliesH
2010-05-19 19:56:32 Scores:3
@Juliet: CW is not only for posts to be "publically editable", it's also to prevent rep-whoring (which is much easier with subjective questions).
fretjeH
2010-05-20 13:28:32 Scores:2

13 answers

Answer 1
Scores:215

Because all those advantages are also disadvantages.

Stateless programs; No side effects

Real-world programs are all about side effects and mutation. When the user presses a button it's because they want something to happen. When they type in something, they want that state to replace whatever state used to be there. When Jane Smith in accounting gets married and changes her name to Jane Jones, the database backing the business process that prints her paycheque had better be all about handling that sort of mutation. When you fire the machine gun at the alien, most people do not mentally model that as the construction of a new alien with fewer hit points; they model that as a mutation of an existing alien's properties.

When the programming language concepts fundamentally work against the domain being modelled, it's hard to justify using that language.

Concurrency; Plays extremely nice with the rising multi-core technology

The problem is just pushed around. With immutable data structures you have cheap thread safety at the cost of possibly working with stale data. With mutable data structures you have the benefit of always working on fresh data at the cost of having to write complicated logic to keep the data consistent. It's not like one of those is obviously better than the other.

Programs are usually shorter and in some cases easier to read

Except in the cases where they are longer and harder to read. Learning how to read programs written in a functional style is a difficult skill; people seem to be much better at