Swift's functional Programming (i)

Source: Internet
Author: User

1. What is functional programming?

Functional programming is the implementation of Alonzo thought in the real world, which treats computer operations as mathematical function calculations and avoids the use of program state and variable objects. The most important basis for functional programming is the lambda calculus. Moreover, the function of the lambda calculus can accept the function as input (the argument) and output (the value of the output), the function of the process is more to enhance the execution of the results of the program rather than the implementation of the procedure, advocating the use of a number of simple execution units to keep the results of the gradual calculation, the layer of the complex computation, rather The killer of functional programming is the growing trend of parallel programming and metadata coding in the world today. The main idea is to write the operation process as much as possible into a series of nested function calls

2. Features of functional programming:

    • functions are "first class citizens": Functions equal to other data types, can be assigned to other variables, can be passed as arguments to another function, or as return values of other functions
    • use only "expression", no statement : "Expression"--is a simple operation process, always has a return value; ' Statement '--performs an operation with no return value. Functional programming requires only expressions, not statements, that is, each step is a simple operation, and there is no return value. However, in the actual I/O is not possible, therefore, in the programming process, functional programming only requires to limit the I/O to the minimum, do not have unnecessary read and write behavior, maintain the simplicity of the computational process.
    • No side effects: function to remain independent, all functions are to return a new value, no other behavior, especially the value of external variables must not be modified
    • do not modify the state: functional programming simply returns the new value without modifying the system variable.
    • Reference Transparency: The function's run does not depend on the external variable or "state", only depends on the input parameters, any time as long as the parameters are the same, the reference function will always get the same return value

Swift's functional Programming (i)

Related Article

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.