Nanyi
Date: April 6, 2012
After more than 50 years of birth, functional programming (functional programming) began to gain more and more attention.
Not only is the oldest functional language Lisp re-emerging, but new functional languages abound, such as Erlang, Clojure, Scala, F #, and so on. Currently the most popular Python, Ruby, Javascript support for functional programming is strong, even the old-style object-oriented Java, process-oriented PHP, are scurried to add to the anonymous function support. There are more and more indications that functional programming is no longer the favorite of academia, and it is starting to be practical in the industry.
Perhaps after "object-oriented Programming", "functional programming" becomes the dominant paradigm of the next programming (paradigm). The programmers of the future will probably have to understand a bit more or less.
However, "functional programming" seems to be difficult, lack of popular introductory tutorials, various introduction articles are filled with mathematical symbols and special terms, let people read such as falling clouds. Even the most basic question, "What is functional programming", can not be easily understood on the Internet.
Here is my "functional programming" study notes, shared, and discussed with you. The content does not involve mathematics (I do not understand lambda calculus), nor does it involve advanced features (such as lazy evaluation and currying), but simply as simple as possible to sort and express, I now understand the "functional programming" and its significance.
I have mainly joined Slava Akhmechet's "functional programming for the Rest of Us".
First, the definition
Simply put, "functional programming" is a "programming paradigm "
(programming paradigm), that is, how to write the methodology of the program.
It belongs to "structured programming", the main idea is to write the operation process as far as possible as a series of nested function calls. For example, there is now a mathematical expression:
(1 + 2) * 3-4
Traditional procedural programming, which may be written like this:
var a = 1 + 2;
var B = A * 3;
var c = b-4;
Functional programming requires the use of functions, which can be defined as different functions, and then written as follows:
var result = Subtract (multiply (add), 3), 4);
This is functional programming.
Second, the characteristics
Functional programming has five distinct characteristics.
1. function is "first Class citizen"
The so-called "first class citizen" refers to a function that, like other data types, is equal, can be assigned to other variables, can also be passed as a parameter to another function, or as a return value for another function.
For example, the print variable in the following code is a function that can be used as an argument to another function.
var print = function (i) {console.log (i);};
[1,2,3].foreach (print);
On functional programming