views:

478

answers:

7

Functional programming is growing quickly. A lot of advices "How to prepare for the future" I've read contain "Learn a functional programming language".

I am new to functional programming. What is its true power? Is it replacing OOP? What fields of programming that functional programming is most powerful? What functional programming language suitable to learn?

Thank you.

+4  A: 

Functional programming lends itself very well to parallel processing, since ideally global state is not an issue. Traditionally, functional programming has been largely for artificial intelligence folks, but it really is nice for any huge-scale application you want to build and run on a farm of machines.

It is not replacing OOP, and I would suggest learning LISP or Haskell if you are interested.

Stuart Branham
I'm no expert on Functional programming. But as I understand it; the multi-threaded functionality is free, so weaker programmers can stay productive with the onslaught of multi-processor chips. +1
John MacIntyre
You're right, except for the "weaker programmers" part. It doesn't make you a "better" developer to write sloppy, side-effect-ridden functions in C# or Java and manage pull off parallel processing.
Stuart Branham
@Stuart B-Thanks, and I wasn't suggesting sloppy programming would make you a better developer. But we all know there are a lot of programmers out there who can't do recursion, redirection, etc ... I kind of wonder if MS coming out with F# wasn't an attempt to keep those programmers able to write 'working' code against the multi-processor machines. Effectively dumbing down parallel processing the same way as they dumbed down Windows programming with Classic VB.
John MacIntyre
+2  A: 

I just attended a lecture on this topic couple of days ago, and it turns out that Haskell is the way to go, if you choose to go down that road. F# is a strong choice too. But I just can't see how Functional programming is going to replace anything. It will be a nice addition to our hackers' "toolboxes" :)

Peter Perháč
+5  A: 

Functional programming and object oriented programming are orthogonal; you can use both things together in some languages, like ruby.

eg: you've got an array of employees objects, and want to get a list of employees names and salaries for employees earning more than 50k

employees.select { |employee| employee.salary > 50000 }.map { |employee| [employee.name, employee.salary] }

will give you an array like

[ ['John', 52000], ['Peter', 60000]]
Maximiliano Guzman
+2  A: 

Functional programming is mostly powerful because it offers concise ways to write algorithms that are more natural for people and easier for compilers to understand. This is largely accomplished by abstracting out processes into common higher-order functions over functions, and providing useful syntax to do so readably and quickly.

Since the results are often simpler and free of difficult-to-manage side effects, they are frequently more readable and less buggy than more procedural alternatives, and they're also frequently easier to parallelize (either explicitly or automatically) which is the source of a lot of recent interest.

mquander
+1  A: 

Hmm. I don't think functional programming replaces OOP. Also, functional programming is not new, it goes back to the 70' and earlier.

Nowadays it's good to know different (programming) languages. So, Java, C/++/# are at least to know. You don't have to become an expert... but know them. These languages aren't plain functional programming languages. For those, see Erlang or Haskell. Look at them and play around to find out what they can do for you...

Cheers, T.

tuergeist
+1  A: 

In addition to the parallel processing advantages that Stuart B mentions, a very powerful feature of functional languages is the ability to treat functions as first-class objects. This means that code can be constructed on the fly and passed around. This is particularly handy for certain types of algorithms (evolutionary algorithms in particular), which is probably why it's so popular in computer science, but it also has practical implications. For example, C# 3.0 borrows this feature in order to implement a lot of the features of LINQ (e.g. dynamically creating code to process query results).

MattK
Agreed. The idea of functions first-class objects is becoming common now, but it really started in functional programming. S expressions? More like sex expressions.
Stuart Branham
A: 

It is very easy to write unit tests for functional-programming fragments because there are no side-effects.

JPS