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

A different way of thinking

FP implies a different way of writing programs, which can sometimes be difficult to learn. In most languages, programming is done in imperative fashion: a program is a sequence of statements, executed in a prescribed fashion, and the desired result is achieved by creating objects and doing manipulations on them, which usually modify the objects themselves. FP is based on producing the desired result by evaluating expressions, built out of functions composed together. In FP, it's usual to pass functions around (as parameters to other functions, or returned as the result of some calculation), to not use loops (opting for recursion instead), and to skip side effects (such as modifying objects or global variables).

Another way of saying this, is that FP focuses on what should be done, rather than on how. Instead of worrying about loops or arrays, you work at a higher level, considering what you need to be done. After getting accustomed to this style, you'll find that your code becomes simpler, shorter, more elegant, and can be easily tested and debugged. However, don't fall into the trap of considering FP as a goal! Think of FP only as a means towards an end, as with all software tools. Functional code isn't good just for being functional... and writing bad code is just as possible with FP as with any other techniques!

主站蜘蛛池模板: 清镇市| 富顺县| 泸溪县| 龙江县| 陈巴尔虎旗| 吴川市| 法库县| 平陆县| 宽城| 富源县| 蓝山县| 绿春县| 岚皋县| 樟树市| 银川市| 驻马店市| 德清县| 财经| 民权县| 湖南省| 扬中市| 冕宁县| 贡山| 龙口市| 广德县| 万盛区| 威远县| 寻甸| 丹阳市| 师宗县| 民权县| 隆子县| 延川县| 涿鹿县| 祥云县| 英德市| 泰和县| 文登市| 泗洪县| 栾城县| 拉萨市|