Functional programming: A step backward (javaworld.com)
You could almost consider it trolling to submit this here. Rather than rehash a discussion of the advantages of functional programming, I would like the comments to focus on a specific issue this article exemplifies: why isn't functional programming catching on?
9 comments
[ 2.1 ms ] story [ 36.8 ms ] threadWhy are these 'scary' code examples used as an indication of what 'functional programming' looks like, instead of entirely reasonable Ruby, javascript or even Java snippets? How is it that proponents continue to fail to make it clear that functional programming can be done, to some extent, in any language and that it still has advantages?
The whole article seemed to me to be a big "waahh this is hard, and looks funny" rather than a serious discussion of the advantages and disadvantages of functional programming.
The Haskell would be much clearer if it wasn't missing a type signature.
These code examples are used by the author of the article to support the point he is trying to make. I imagine these are probably pretty good examples to use for the target demographic of javaworld.
About the 'scary' code examples, one is perfectly reasonable and the other is taken quite out of context. I think it is the case that one can always produce unreadable code regardless of language.
Proponents who are behind particular language and maybe even a specific compiler are promoting exactly those. Of course, FP-style can be used in any language that supports first-class functions, proper closures, and tail call optimization. There are plenty examples of mainstream languages with the first of those. The remainder are not as widespread. However, the advantages of many modern FP languages go well beyond that of the key features pioneered by LISP and the Landin's unimplemented language ISWIM from the 1960s. When people tout Haskell, they are probably not doing so just for the first-class functions. They probably are enamored by the sophisticated static type system, type classes, and many, many more important features which cannot be easily emulated in a mainstream language because they require language and compiler support. Another example: Because functional style often entails recursion, the lack of proper tail call optimization is a huge barrier.
The primary advantage of FP that the author of the article concedes is concurrency benefits from pure FP. Purity (statelessness) requires considerable language support. In most mainstream languages, state is just too pervasive to make any substantial purity guarantees for concurrency. FWIW, I think the jury is still out on the concurrency question in FP.
The fact is that many mainstream languages are becoming quite multi-paradigm. I think many in the FP community view that development positively. In the very least, ubiquity of some functional features will make it easier for people to transition to full-blown modern FP languages. However, having mainstream languages adopt just one or two features pioneered decades ago isn't entirely satisfactory. There is so much more in modern FP languages, but that is where the community splinters dramatically.
That said, obviously JavaScript is one of the most successful programming languages in history (with no slight intended towards any other mainstream language). The other mainstream languages have also achieved great success through many years of hard work. It is great that people are rediscovering FP there where appropriate. It should be interesting to see how these languages ultimately evolve.