38

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?

  • 6
    Very big in AI programming. – aqua Feb 25 '11 at 3:54
  • 3
    @aqua - shouldn't that be an answer for why not? – Martin Beckett Feb 25 '11 at 16:26
  • 5
    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
  • 2
    @apoorv020: And generics, tuples and garbage collection and... all originated in functional languages. – Jon Harrop Feb 23 '12 at 15:20
60

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.
  • 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
  • 1
    @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
9

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.

  • Maybe it doesn't really need a name then? Isn't it simply 'correct' program design? – user251748 Sep 8 '17 at 18:14
4

When you are beginning, functional programming is the best thinking model. 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 OO down on me, or that OO is the solution for everything. Just make sure that whatever approach you use, it 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.

  • 1
    +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
  • 1
    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
  • "Common sense is the most fairly distributed thing in the world, for each one thinks he is so well-endowed with it that even those who are hardest to satisfy in all other matters are not in the habit of desiring more of it than they already have." - Descartes – user251748 Sep 8 '17 at 18:22
3

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

  • OOP emphasizes nouns. Sometimes it's the nouns that matter. How do we know which? – False Dilemma. System Halted – user251748 Sep 8 '17 at 18:27
3

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).

  • So, isn't that simply the definition of 'better'? Why would we want to do anything other than what you have described? – user251748 Sep 8 '17 at 18:29
2

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)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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