Idea of functional programming

Source: Internet
Author: User

Idea of functional programming

 

What is functional programming? In mathematics, a function is a relation that maps each element in a set to the unique element in another set. A function is a rule that assigns a unique output value to each input ". This "rule" can be represented by function expressions, mathematical relationships, or a simple table listing the input and output values. The most important feature of a function is its determination, that is, the same input always corresponds to the same output (note that the opposite is not necessarily true ). From this perspective, you can think of a function as a "machine" or "black box", which converts valid input values to unique output values. Generally, the input value is called a function parameter and the output value is called a function value.
John Hughes, author of why functional programming matters, explains that modularity is the key to successful programming, and functional programming can greatly improve modularity. In function programming, programmers have a natural framework to develop more refined, smaller, simpler, and more general modules, and then combine them together. The basic features of functional programming are:
Rich Data Types;
The function is an operational element;
Save data in the function;
Operations in a function have no side effects on the function.
Function programming only describes the operations performed on program input, and does not need to use temporary variables to save intermediate results. The key is to capture "what and why", rather than "how to do ". Compared with procedural programming that focuses on executing continuous commands, functional programming focuses on the definition of functions rather than the implementation of state machines. It is a programming style that emphasizes expression calculation rather than command execution. An expression is composed of functions and basic values. It is similar to calling a function using parameters (the beautiful description of the function can be seen in functional programming for the rest of us).
Why does JavaScript use functional programming? In fact, whether it is object-oriented or process-oriented, we need simple, efficient, and highly maintainability and reusable implementation. Some features of JavaScript meet this demand.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.