Hacker News new | ask | show | jobs
by katovatzschyn 5436 days ago
I maintain that the best way to get started with functional programming is to pick a functional language and try to write a program with it.
3 comments

Exactly this.

Trying to write pure functions in a standard language is completely the wrong approach. You might as well say, tie one hand behind your back and try to write with the other hand.

Many functional languages don't require pure functions.

Many functional languages have garbage collectors, and they are fundamental for writing pure functional data structures. (It's almost impossible to properly emulate this in, say C, especially if your structures have cycles)

Many functional languages have other great features like type inference, macros, data patterns and more. Just using an existing language won't give you any taste for these.

> Many functional languages don't require pure functions.

Yes. Though I would suggest a newcomer to pick a language that requires purity, in order to make the transition cleaner.

I would finesse that slightly and say that the way is to pick a multi-paradigm language (OCaml, Scala, etc) and gradually work in more FP as you get more comfortable with it. E.g. you can start gently by simply replacing for loops with maps or folds, then introduce HOFs/closures, etc etc.
The point is not: how. The point is: why.
There are plenty of resources on why you would want to program functionally.

One of the most notable one is:

http://www.cs.utexas.edu/~shmat/courses/cs345/whyfp.pdf

Benefits include: Easier reasoning about code correctness. More powerful abstractions leading to clearer and more succint code. Easier mechanical refactoring of code. Easier parallelism. More powerful compiler optimizations.

Great, now answer: why not.
Depends on what you are looking for.

Apart from any benefit from actually using any language or tool, there's also the joy of learning.