標籤:

學習函數式編程有什麼用?


又是這種問題, 有些事沒有強調過, 順道在這裡強調一下:

FP沒有一個公認的定義

FP沒有一個公認的定義

FP沒有一個公認的定義

"Functional Programming" is a thing

It isnt. Its one of the worst-defined terms in CS--maybe even worse than "OOP", but a tad better than "declarative programming". Figuring out whether a language is "functional" is an exercise in anthropology, not computer science.

There is no technical definition of "functional programming" that would not cause a lot of people to complain. Some definitions are too broad--if all you want are lambdas, then everything from C++ to Java to Python is suddenly functional, and only C and assembly arent! If you take a mathematical definition, then only Coq, Agda and friends are functional because even Haskell admits partial functions and non-termination. And exceptions. Oh god, the exceptions!

via What are some myths about functional programming and functional programming languages?

再舉些例子, WTF is Funcitonal Programming系列:

http://blog.enfranchisedmind.com/2009/05/scala-not-functional/

http://james-iry.blogspot.com/2009/05/erlang-is-not-functional.html

http://conal.net/blog/posts/the-c-language-is-purely-functional

所以這個問題基本沒有意義, 雖然洋洋洒洒列各種語言特性出來說各種牛逼各種好應該會多點贊, 但是你為什麼不問問神奇海螺呢, 或者問某個feature 有什麼用還是能答一下的, 就像這個一樣:

為什麼諸多編程語言都將模式匹配作為重要構成?


預防老年痴呆


不搞工程搞學術的話用函數式非常爽,你能把state of the art的演算法都抽象出來統一實現了,問題立刻可以看得非常透徹,那裡不同哪裡可以改進也一眼就能看出來,並且修改、組合演算法也非常方便。

寫論文的時還可以不動腦子直接翻譯成數學表達式,比上偽代碼逼格高多了。


當年smalltack是個OOP純度很高的語言 導致寫個小几把玩意都得寫一大堆代碼


開拓下視野沒什麼不好,何況在這高並發的時代


推薦閱讀:

TAG:函數式編程 |