官术网_书友最值得收藏!

Functional programming

Functional programming is a paradigm that originates from the lambda calculus. Without diving too much into the lambda calculus (λ-calculus), this roughly means that computation is performed through the use of mathematical functions, which avoids mutable data and changing state of surroundings. The idea of a strictly functional language is that all function outputs are dependent only on the input and not on any external state. Since Python is not strictly a programming language, this doesn't necessarily hold true, but it is a good idea to adhere to this paradigm as mixing these can cause unforeseen bugs as discussed in Chapter 2, Pythonic Syntax, Common Pitfalls, and Style Guide.

Even outside of functional programming, this is a good idea. Keeping functions purely functional (relying only on the given input) makes code clearer, easier to understand, and better to test as there are less dependencies. Well-known examples can be found within the math module. These functions (sin, cos, pow, sqrt, and so on) have an input and an output that is strictly dependent on the input.

主站蜘蛛池模板: 县级市| 泗水县| 保定市| 伊金霍洛旗| 鹰潭市| 鞍山市| 丰原市| 谷城县| 甘肃省| 栾川县| 疏附县| 沈丘县| 甘泉县| 祁东县| 渭南市| 建湖县| 开封县| 那曲县| 大同县| 夏邑县| 中山市| 连州市| 宜州市| 罗定市| 铅山县| 民县| 武宣县| 渝中区| 武邑县| 台州市| 蒙阴县| 玉龙| 芷江| 犍为县| 马关县| 汝阳县| 丰镇市| 文化| 阿勒泰市| 共和县| 金乡县|