我在这里看到很多关于函数式语言的讨论。为什么你要使用传统语言而不是传统语言呢?他们在哪些方面做得更好?他们更不擅长什么?理想的函数式编程应用程序是什么?


当前回答

我一定是糊涂了,但我还是不明白。是否有像f#这样的函数式语言编写的小型应用程序的实际例子,你可以查看源代码,并了解如何以及为什么使用这种方法比c#更好?

其他回答

我不认为函数式编程方法“流行起来”有任何问题,因为它(作为一种编程风格)已经被使用了大约40年。每当OO程序员编写有利于不可变对象的干净代码时,这些代码就是借用了函数概念。

然而,这些天来,强制函数式风格的语言正在获得大量的虚拟墨水,这些语言是否会在未来占据主导地位是一个悬而未决的问题。我自己的怀疑是混合的、多范式的语言,如Scala或OCaml 将很可能统治“纯粹的”函数语言,就像纯粹的OO语言(Smalltalk、Beta等)影响了主流编程一样,但还没有成为最广泛使用的表示法。

最后,我忍不住要指出,你对FP的评论与我几年前从过程程序员那里听到的评论高度相似:

(恕我直言,这是神话)“普通”程序员不理解它。 这并没有被广泛教授。 任何你能用它来写的程序,都能用现有的技术以另一种方式来写。

Just as graphical user interfaces and "code as a model of the business" were concepts that helped OO become more widely appreciated, I believe that increased use of immutability and simpler (massive) parallelism will help more programmers see the benefits that the functional approach offers. But as much as we've learned in the past 50 or so years that make up the entire history of digital computer programming, I think we still have much to learn. Twenty years from now, programmers will look back in amazement at the primitive nature of the tools we're currently using, including the now-popular OO and FP languages.

除了其他答案之外,用纯函数术语来描述解决方案可以迫使人们更好地理解问题。相反,用函数式的思维方式会培养出更好的解决问题的能力。

*要么是因为功能范式更好,要么是因为它可以提供额外的攻击角度。

在我看来,那些从未在本科阶段学习过Lisp或Scheme的人现在正在发现它。与这个领域的许多事情一样,有一种炒作和创造高期望的倾向……

一切都会过去的。

函数式编程很棒。然而,它不会统治世界。C、c++、Java、c#等语言仍将存在。

我认为这会带来更多的跨语言能力——例如,用函数式语言实现一些东西,然后用其他语言访问这些东西。

你最近有关注编程语言的发展吗?所有主流编程语言的每一个新版本似乎都从函数式编程中借用了越来越多的特性。

Closures, anonymous functions, passing and returning functions as values used to be exotic features known only to Lisp and ML hackers. But gradually, C#, Delphi, Python, Perl, Javascript, have added support for closures. Its not possible for any up-and-coming language to be taken seriously without closures. Several languages, notably Python, C#, and Ruby have native support for list comprehensions and list generators. ML pioneered generic programming in 1973, but support for generics ("parametric polymorphism") has only become an industry standard in the last 5 years or so. If I remember correctly, Fortran supported generics in 2003, followed by Java 2004, C# in 2005, Delphi in 2008. (I know C++ has supported templates since 1979, but 90% of discussions on C++'s STL start with "here there be demons".)

是什么让这些功能吸引程序员?这应该是显而易见的:它帮助程序员编写更短的代码。如果想要保持竞争力,未来所有的语言都将至少支持闭包。在这方面,函数式编程已经成为主流。

大多数应用程序都很简单 可以用正常的面向对象方法解决

谁说不能用函数式编程来处理简单的事情?并不是每个函数程序都需要是编译器、定理证明器或大型并行通信交换机。除了更复杂的项目外,我还经常使用f#来编写临时脚本。

它之所以流行起来,是因为它是控制复杂性的最佳工具。 看到的: ——西蒙·佩顿-琼斯演讲《哈斯凯尔的味道》幻灯片109-116 ——Tim Sweeney的《下一个主流编程语言:游戏开发者的视角