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

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.

主站蜘蛛池模板: 武平县| 得荣县| 新兴县| 定襄县| 湖口县| 岱山县| 邢台县| 澜沧| 滦南县| 盘山县| 米泉市| 博兴县| 台安县| 陇西县| 西畴县| 晋宁县| 凤山市| 崇左市| 东台市| 中超| 遂溪县| 宜昌市| 营口市| 义乌市| 织金县| 永年县| 长岭县| 瑞金市| 新津县| 嘉荫县| 镇远县| 浮山县| 霍山县| 怀集县| 姚安县| 巴青县| 突泉县| 黄山市| 武城县| 老河口市| 军事|