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

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.

主站蜘蛛池模板: 山东省| 金堂县| 永济市| 昭觉县| 吴江市| 资阳市| 唐山市| 确山县| 隆化县| 京山县| 文水县| 扎鲁特旗| 桑植县| 济南市| 乐平市| 陵川县| 黄山市| 临颍县| 葫芦岛市| 开鲁县| 甘德县| 青铜峡市| 石屏县| 喜德县| 宁海县| 宿松县| 石嘴山市| 石首市| 承德市| 元谋县| 甘谷县| 肥城市| 巴里| 两当县| 蓝山县| 石景山区| 洛隆县| 长治市| 千阳县| 扶余县| 德州市|