News for hackers. Stuff that matters.
Re:Functional Programming in 5 Minutes by a-nikolaev on Sunday May 19, 2013 @04:46PM (#5734329)
I would like to add that recursive calls can be nicer than loops, when multiple conditions or branching are possible in the loop body.

An equivalent implementation with while loops, if conditions, continues, and breaks are usually harder to design correctly than a good recursive function.

Functional programming encourages use of small simple datatypes. Tuples instead of small structs. Lists instead of more complex container types. First-class functions instead of classes.

However, IMO 'purity' is a bit of a buzzword when applied to functional programming. You may disagree, but that's how I feel about it..

Re:Functional Programming in 5 Minutes by Peaker on Sunday May 19, 2013 @05:06PM (#5734385)
I think recursive solutions are often very nice indeed. But at worst, recursive solutions are sometimes worse than structured loops, because you can use recursions very much like a free-style goto, allowing your code to have even less restrictive structure than loops. That's why directly recursive code is usually discouraged and reusing recursive combinators is encouraged.

I agree that purity is often used as a buzzword.

To parody this, Conal Elliott wrote the "C is purely functional" blog post: http://conal.net/blog/posts/the-c-language-is-purely-functio...

To resolve this, a nice suggestion is to use the term "denotative programming". That is, programming where types and values have mathematically simple denotations that predictably compose exactly according to the syntactic composition being used.

Re:Functional Programming in 5 Minutes by a-nikolaev on Sunday May 19, 2013 @05:49PM (#5734544)
Thanks for the idea of "denotative programming". I think, it can be a really nice paradigm for teaching programming and math together.
Re:Functional Programming in 5 Minutes by ufo on Sunday May 19, 2013 @06:38PM (#5734698)
Tail-recursive calls are essentially gotos, but a little more well behaved (if you try to put state into explicit parameters instead of mutable variables).
Re:Functional Programming in 5 Minutes by derleth on Sunday May 19, 2013 @11:26PM (#5735711)
> I would like to add that recursive calls can be nicer than loops

Having a good library of higher-order functions that encapsulate common recursion patterns is a lot nicer than doing recursion by hand, or having to read code where someone did recursion by hand and you have to not only figure out how the recursion works, but whether the author did anything wrong.

Higher-order functions are control structures, and we should encourage their use for all the same reasons we encourage the use of while loops in preference to people building their loop structures by hand out of gotos and conditional gotos.

Re:Functional Programming in 5 Minutes by eru on Monday May 20, 2013 @06:11AM (#5736812)
As another nice effect, higher-order functions (or as we call them in their use as control structures: combinators) unify data structure and control structures. E.g. folding over a list is equivalent to various loops, the Monad instance of Maybe represents simple exception handling, trees and their traversal are identifiable in some sense, etc.

At least in lazy, statically typed functional languages, like e.g. Haskell.

Re:Functional Programming in 5 Minutes by Paradigma11 on Monday May 20, 2013 @06:56AM (#5736917)
I agree but using mutual recursion to model simple state machines is very nice.