推荐一篇介绍函数式编程(functional programming)的文章

说实话,对于函数式编程(functional programming),我一直云里雾里,不大明白。今天读到一篇文章:An introduction to functional programming,感觉写的不错,读完之后,至少觉得自己入门了。我把其中最核心的一段话摘录出来,并做了翻译:

When people talk about functional programming, they mention a dizzying number of “functional” characteristics. They mention immutable data, first class functions and tail call optimisation. These are language features that aid functional programming. They mention mapping, reducing, pipelining, recursing, currying and the use of higher order functions. These are programming techniques used to write functional code. They mention parallelization, lazy evaluation and determinism. These are advantageous properties of functional programs.  

Ignore all that. Functional code is characterised by one thing: the absence of side effects. It doesn’t rely on data outside the current function, and it doesn’t change data that exists outside the current function. Every other “functional” thing can be derived from this property. Use it as a guide rope as you learn.

译文:

当人们谈论起函数式编程,他们总会提到一堆令人眼花缭乱的“函数式”特性。他们提到“不可变数据”,“`first class functions`”和“尾调用优化”。这些是辅助函数式编程的语言特性。他们提到“`map/reduce`”,“流水线”,“递归”,“`currying`”和“高阶函数”。这些是写函数式代码的编程技术。他们提到“并行”,“惰性求值”和“确定性”。这些是函数式程序的优良特性。  

忽略上面提到的这些,函数式代码被一个特性所决定:没有副作用,即它不依赖于也不会改变当前函数以外的数据状态。其它所有“函数式特性”均由此特性衍生出来。  

发表评论

电子邮件地址不会被公开。 必填项已用*标注

This site uses Akismet to reduce spam. Learn how your comment data is processed.