在函数式编程中,函数构成了计算的构建块(In functional programming, functions constitute the building blocks of computing)

函数式编程是一种编程范式,它规定了一种不同的算法方式来思考问题并为其编程解决方案。将其与面向对象编程进行对比,在 OOP 中,主要抽象是类/对象,而在函数式编程中,主要抽象是函数。在 OOP 中,对象构成了计算的构建块。同样,在函数式编程中,函数构成了计算的构建块。

函数式编程强加了声明式编程风格,即我们通过表达式或声明进行编程(计算以函数/表达式——黑盒子的形式表达)。声明式编程风格是关于定义要做什么而不是如何做,将其与命令式编程进行对比,后者是关于定义要做什么以及如何做。简单来说,在声明式编程中,就是拥有一个抽象层,从而产生富有表现力的代码。函数式编程往往是声明式的,声明式的思考和编码往往会产生更好的、可读的和富有表现力的代码。声明式与命令式风格的一个例子是:

函数式编程将函数和函数的组合表达放到了第一位。

————————

Functional programming is a programming paradigm, which stipulates a different algorithmic way to think about problems and program solutions for them. Compared with object-oriented programming, in OOP, the main abstraction is class / object, while in functional programming, the main abstraction is function. In OOP, objects constitute the building blocks of calculation. Similarly, in functional programming, functions constitute the building blocks of calculation.

< strong > functional programming imposes a declarative programming style < / strong >, that is, we program through expressions or declarations (calculations are expressed in the form of functions / expressions – black boxes)< Strong > declarative programming style is about defining what to do, not how to do it < / strong >, which is compared with imperative programming, which is about defining what to do and how to do it. Simply put, in declarative programming, it is to have an abstraction layer to produce expressive code. Functional programming is often declarative, and declarative thinking and coding often produce better, readable and expressive code. An example of declarative and imperative styles is:

Functional programming puts the combined expression of function and function in the first place.