Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.
Trending News
Can someone tell me a good argument and use case as to why they would use a purely functional language rather than an OO language?
1 Answer
- oyubirLv 63 years agoFavorite Answer
I am a huge fan of functional programming, so I can think of many reason to like functional languages.
But I must say that I am quite surprised by your dichotomy. You know that there are other paradigms than functional and oo? Some of them far more popular than functional programming.
So, even I (who, again, like functional programming) would say "you should at least consider procedural programming, before forcing yourself to choose between functional and oo").
To make a technical analogy, that would be as asking "What are the argument to use firefox OS rather than an iPhone". Well, there are probably lot of argument a firefox OS fan could give you. But the alternative is a little bit extreme. If you don't like iphone, you are not forced to use firefox OS; that is forgetting the obvious Android.
That being said:
1) Why not OO:
OO is not really good for cooperative project (which is a pity, since it is usually one of the first argument given in favor of OO. But, well, I have been saying that for decades now, and now, Bjarne Stroustrup, is, roughly, saying the same!).
Roughly inheritance + multiple concurrent authors => multiple inheritance (which is never a good idea)
So, there are reason to dislike OO.
I don't want to start a OO vs procedural war here, so let's immediately say that this are subjective reason, and that OO partisan have good counter argument to that. But well, you are asking for arguments : there are many good points against OO. Whether the advantages of OO overcome the drawbacks is another debate that we don't need to solve here. The point is that there are drawbacks. See any "OO vs procedural" debate to see many opinions about why OO is not ideal.
2) Why functional
(Again, that is not the same thing. You can conclude that you don't want OO, because of arguments of "1)", that doesn't mean at all that the solution is functional. Most of the people who decide that they don't want OO, decide to use procedural, not functional).
Functional programming is very useful in a mathematical context. Because the programming follows the way of thinking in math.
Eg, saying factorial(n) = 1 if n=0, n*factorial(n-1) else
is both a mathematical definition of factorial, and a functional program.
In math, most of the time, you describes values (not necessarily scalar values ; also sets, functions, subspaces, etc) not actions. In math, most of the time, the "if" is a functional "if", not a classical "if" (the "if" of a math text, in C, would be translated by a ternary operator, a?b:c, not by a "if". The ternary operator is sometimes called "functional if").
So functional programming makes this quite natural
Likewise, in math, often when you combine computation, you do it by combining functions, not sequencing them (the "o" is a classical operator in math. There is no such things as ";" in most math description). That is very compatible with lambda calculus.
Math is not the only reason.
I've also used functional programming for lot of AI project. Because it makes it easy to reason on functions themselves (treat functions as object of the language, without strict dichotomy between the functions and the data they operate one). That is a very natural programming paradigm when you want to use reflective programming (program than can reason on themselves, or modify themselves).
Even in meta-programming project (which could be for AI, but not only. Some high level compiling may take advantage of that as well). For example partial evaluation is perfectly natural using functional programming. And is not at all natural in other paradigms.
(Or as Eddie J said, functional programming can ease parallel computing. For example, if you want to use branch&bound on several processor)