Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

What is the deal with functional programming? I see talk about it a lot but to be honest I've never found them at all useful. Why do so many universities apparently teach them?

share|improve this question
6  
Very big in AI programming. –  aqua Feb 25 '11 at 3:54
2  
@aqua - shouldn't that be an answer for why not? –  Martin Beckett Feb 25 '11 at 16:26
3  
I would also like to point out that even traditional OO languages are beginning to include concepts from functional programming. Linq (in .NET), being a case in point. –  apoorv020 Feb 25 '11 at 16:34
    
I think functional programming exercises your brain more, and can lead to really pithy code. So it's pretty cool. –  Adel Sep 11 '11 at 21:16
1  
@apoorv020: And generics, tuples and garbage collection and... all originated in functional languages. –  Jon Harrop Feb 23 '12 at 15:20

7 Answers 7

up vote 46 down vote accepted

Start with Why Functional Programming Matters. Then move to Why Why Function Programming Matters Matters. A few bullets:

  • Functional programming allows you to reason about problems differently
  • Functional abstraction is very powerful and allows you to DRY up your code in ways not available to other paradigms
  • In our multi-core future, functional languages may be easier to split into simultaneous tasks (though not-strictly-functional languages are working hard on the problem as well).
  • It's easier to prove that programs written in pure functional languages (no side effects) are mathematically correct.
share|improve this answer
5  
+1 - These are all excellent points, and they're explained both more concisely and with more exact detail than what I tried to do. –  jmort253 Feb 25 '11 at 3:27
1  
With your fourth point, did you mean the language can be proven correct, or programs written in the language? Anyway, both impure languages and programs written in impure languages can be proven correct, it's just much harder and messier. –  Jörg W Mittag Feb 25 '11 at 9:34
    
@Jörg W Mittag, it is much easier to reason about the properties of the language itself too. Denotational semantics is trivial for the functional languages, and quite complicated for the imperative. –  SK-logic Feb 25 '11 at 9:46
    
funny how the second link provides some "explicit" arguments, knowing I don't even read the 1st link. –  jokoon Feb 25 '11 at 9:59
    
+1: Great answer. I especially like how you put bullet points #1 and #2 to words. –  Jim G. Feb 25 '11 at 12:33

Functional Programming concepts build a foundation that will change the way you think and help you solve real world problems.

The concept is similar to why we all learn Multi-Variable Calculus, Algebra, and/or Engineering Physics as Computer Science majors, even though we may not ever need that specific knowledge in our careers.

This is why Law Schools love candidates with a B.S in Mathematics. Studying Mathematics teaches you to think about multiple concepts in a logical manner, and functional programming teaches you abstractions and many other important concepts that help you break down problems and look at them in a different light.

In summary, functional programming helps teach you how to learn.

share|improve this answer

When your beginning, functional programming is the best thinking modal. Because most of your programs will not require object-orientation. At least that's been my experience.

However, now that I get into some apps, that require separation of display and logic, that's when I started to separate all the logic and display code, to make it easier for each do what it's best at.

But you won't know why to do that, unless you master functional first. I never liked people shoving down oo to me, that oo is solution for everything, just make sure whatever approach you use, makes sense for what you are working on, and isn't too steep a learning curve to take too much time away from the work you get paid to do.

share|improve this answer
    
+1 - I like that you point out using the best technique for the job: Make sure it makes sense. –  jmort253 Feb 25 '11 at 3:29
    
Sadly, common sense is rare in our industry. Because each of us has completely different experiences, which because of the mistakes we make are different, each of us develop's different habits, and why we do them...Such as adapting source control, makes no sense to anyone who has always worked by themself. –  crosenblum Feb 25 '11 at 16:26

While I personally find pure functional languages too restrictive for entire programs, you might be surprised how often portions of a program in a more traditional language work well using functional programming concepts.

For example, using pure functions can make them easier to unit test and easier to make thread safe. The concepts are well worth knowing about.

share|improve this answer

Because it emphasizes verbs, not nouns. Sometimes it's the verbs that matter.

share|improve this answer

Maybe because universities want to teach something from all programming paradigms, and for certain things functional programming is better (like describing game characters movement and describing animations)

share|improve this answer

Because in general it uses less code to accomplish the same task. Less code to write, is less code to maintain. Besides being less code, it is also tends to have less state, and thus it is a little simpler to reason about (once you're used to it).

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.