views:

526

answers:

13

Functional programming seems to be a paradigm in computer science which has more and more echo.

I wonder which kind of problems are better solved with a functional programming approach rather than with a more traditional object oriented approach.

Thank you.

+5  A: 

Functional programming is great for creating programs that can undergo parallel execution since they discourage the use of global states.

vanslly
+5  A: 

Functional languages are used a lot in maths and statistics.

Galwegian
+2  A: 

I agree with Galwegian -

"Functional languages are used a lot in maths and statistics."

However, those are not the only uses. As functional programming languages become more mainstream, youll likely starting finding business classes/libraries/software written written in these languages.

JTA
+3  A: 

To further on the parallel execution point, functional languages tend to be good for graphical modelling, such as ray-tracing.

DrHazzard
+2  A: 

Pretty much anything that has a lot of maths.

TraumaPony
+1  A: 

If you're writing C++ templates, you're working in a pure functional language.

Ferruccio
+7  A: 

This is close to these other questions.

Why functional languages?

What are the benefits of functional programming?

Brian
+2  A: 

For example the functional language ML is nice for implementing compilers and other applications manipulating trees.

Morten Holdflod Møller
+1  A: 

XSLT is an example of a functional programming language for doing transformations of data or documents represented as XML -- admittedly a very verbose and very limited one. If I remember correctly XQuery is also purely functional. The tricks is that without any concept of global state they arely on a host program to supply the data and consume their results. This helps keep XSLT programs (stylesheets) pure and reusable, but you need to add some sort of (imperative) framework to use them as part of a general-purpose processing system.

pdc
+5  A: 

Functional programming is best suited for most kinds of problems, including anything you would normally use object-oriented programming for, except for maybe problems that require the storing of a lot of state or other side effects. Aside from that, FP handles complex problems much more gracefully than OOP, as a lot of it comes from a mathematical background (starting with the lambda calculus). You have much more flexibility as far as abstraction and composition go. An object-oriented program with a lot of design patterns could be refactored using more functional constructs which will allow you to do the same thing without the boilerplate structures that design patterns make you write. In addition to mathematics and parsing, FP has also been extensively used in artificial intelligence (particularly Lisp).

Mark Cidade
+1  A: 

Basic spreadsheets can be seen as functional programs... :)

Morten Holdflod Møller
+1  A: 

Data Structures. Example: Compare the imperative implementation of a Fibonacci Heap (often used as a priority queue) with the functional implementation. Often the functional code will be less than 100 lines of code whereas the imperative implementation can be many more lines of code.

fooledbyprimes
+1  A: 

and parsing...

Jon Harrop