6 ms·
What is functional programming?
- veddox 11y agoThe title is rather misleading, IMO. What the article is really about is side-effect free programming. This is indeed covered very well, the author manages to explain both what side-effects are and why it makes sense to avoid them in a clear, succinct style with useful examples. Thumbs up for that! However, functional programming is about much more than avoiding side effects. AFAIK, the defining factor for whether a give language can be classed as functional is whether it has functions as first-class objects. That means: can functions be created (and returned) by other functions? Can functions be passed as parameters to other functions? This is a huge area that was completely ignored in the blog post.
- dozzie 11y agoAnd for good reason, in my opinion. Perl, Python, and JavaScript are nowhere near being functional languages, but they all allow creating functions (those are typically called "closures") and passing them around. Yes, all these languages allow for functional programming, but it's not their primary paradigm, and not the one that is only natural when you use the language. There must be something different that makes a language functional.
- Mithaldu 11y ago> There must be something different that makes a language functional. The main problem is that "functional" is not a binary attribute, but a matter of degrees. Technical no single language is entirely functional. However all of them are functional to smaller or larger degrees.
- veddox 11y agoI think I didn't express myself quite right. As mightybyte says in his comment on the successor thread to this one (https://news.ycombinator.com/item?id=10812198 https://news.ycombinator.com/item?id=10812198), functional programming is a programming paradigm that focuses on functions as the basic building blocks of a program. (As opposed to, say, objects in OOP.) Everything else that is part of FP flows from this - if you will, that is the essence of functional programming. However, "it has an emphasis on functions" is a rather wishy-washy definition for a functional programming language. Thus I touted first-class functions as a working definition for how to classify a language as functional. It's not the whole story, but it indicates an underlying philosophy. And of course, languages almost always fall somewhere on the continuum of the paradigm spectrum. Even many Lisp dialects have become multi-paradigm nowadays. "Functional" simply means that a language supports functional programming well.
- alisey 11y agoIn part 2 he writes about why it's not the essence of functional programming: http://blog.jenkster.com/2015/12/which-programming-languages-are-functional.html http://blog.jenkster.com/2015/12/which-programming-languages...
- k__ 11y agoReally? A short time ago I read an article (can't find it sadly) where some guy ranted about how everyone thinks FP is about first class functions, but this feature was the least important.
- veddox 11y agoI learned functional programming from "Common Lisp: a gentle introduction to symbolic computation" (David Touretzky) and "Structure and Interpretation of Computer Programs" (Abelson and Sussman). If you have better sources, I am open to rethinking what I said.