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

The benefits of functional programming

Writing TypeScript code using a functional programming style has many benefits, among which we can highlight the following:

  • Our code is testable: If we try to write our functions as pure functions, we will be able to write unit tests extremely easily. We will learn more about pure functions later in this chapter.
  • Our code is easy to reason about: Functional programming can seem hard to understand for developers with a lack of experience in functional programming. However, when an application is implemented correctly using the functional programming paradigm, the results are very small functions (often one-line functions) and very declarative APIs that can be reasoned about with ease. Also, pure functions only work with their arguments, which means that when we want to understand what a function does, we only need to examine the function itself and we don't need to be concerned about any other external variables.
  • Concurrency: Most of our functions are stateless, and our code is mostly stateless. We push state out of the core of our application, which makes our applications much more likely to be able to support many concurrent operations and it will be more scalable. We will learn more about stateless code later in this chapter.
  • Simpler caching: Caching strategies to cache results become much simpler when we can predict the output of a function given its arguments.
主站蜘蛛池模板: 嘉黎县| 图木舒克市| 青海省| 阳高县| 东至县| 额敏县| 鹿泉市| 锦屏县| 滦平县| 五原县| 依安县| 马边| 苏尼特右旗| 大渡口区| 息烽县| 门源| 林西县| 灵台县| 兰西县| 华宁县| 三江| 威海市| 双流县| 南雄市| 黎平县| 临泽县| 万全县| 岢岚县| 通辽市| 朔州市| 阿拉善右旗| 承德县| 新野县| 茌平县| 克山县| 高台县| 宜宾县| 波密县| 忻州市| 扎囊县| 鞍山市|