我在这里看到很多关于函数式语言的讨论。为什么你要使用传统语言而不是传统语言呢?他们在哪些方面做得更好?他们更不擅长什么?理想的函数式编程应用程序是什么?
当前回答
讨论中忽略的一点是,最好的类型系统存在于当代FP语言中。更重要的是,编译器可以自动推断所有(或至少大部分)类型。
有趣的是,在编程Java时,有一半的时间花在编写类型名上,然而Java到目前为止还不是类型安全的。虽然你可能从来没有在Haskell程序中写过类型(除非作为一种编译器检查的文档),但代码是100%类型安全的。
其他回答
我敢打赌,当你使用以下方法时,你并不知道你在进行函数式编程:
Excel公式 石英的作曲家 JavaScript Logo(海龟图形) LINQ SQL js(或Lodash), D3
我一直对“下一件大事”持怀疑态度。很多时候,下一个大事件纯粹是历史的偶然,无论技术好坏,它都在正确的时间出现在正确的地点。例如:c++, Tcl/Tk, Perl。所有的技术都是有缺陷的,都非常成功,因为它们被认为要么解决了当时的问题,要么与根深蒂固的标准几乎相同,或者两者兼而有之。函数式编程可能确实很棒,但这并不意味着它会被采用。
But I can tell you why people are excited about functional programming: many, many programmers have had a kind of "conversion experience" in which they discover that using a functional language makes them twice as productive (or maybe ten times as productive) while producing code that is more resilient to change and has fewer bugs. These people think of functional programming as a secret weapon; a good example of this mindset is Paul Graham's Beating the Averages. Oh, and his application? E-commerce web apps.
自2006年初以来,也有一些关于函数式编程和并行的讨论。因为像Simon Peyton Jones这样的人至少从1984年开始就一直在担心并行性,所以在函数式语言解决多核问题之前,我不会屏住呼吸。但它确实解释了目前一些额外的话题。
In general, American universities are doing a poor job teaching functional programming. There's a strong core of support for teaching intro programming using Scheme, and Haskell also enjoys some support there, but there's very little in the way of teaching advanced technique for functional programmer. I've taught such a course at Harvard and will do so again this spring at Tufts. Benjamin Pierce has taught such a course at Penn. I don't know if Paul Hudak has done anything at Yale. The European universities are doing a much better job; for example, functional programming is emphasized in important places in Denmark, the Netherlands, Sweden, and the UK. I have less of a sense of what's happening in Australasia.
我不认为函数式编程方法“流行起来”有任何问题,因为它(作为一种编程风格)已经被使用了大约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.
我个人认为,对于分布式系统和多线程/并行编程,函数式编程将很快取得突破。只要它通过编程库与现有的OOP范式集成。所以…在我看来,纯功能的方法仍将停留在学术上。
因为FP在生产力、可靠性和可维护性方面有显著的好处。多核可能是一个杀手级应用程序,最终让大公司在大量遗留代码的情况下转换。此外,即使是像c#这样的大型商业语言,也因为多核问题而呈现出一种独特的函数风格——副作用根本不适合并发性和并行性。
我不认为“普通”程序员不能理解它。他们会的,就像他们最终理解了面向对象编程一样(它同样神秘和怪异,如果不是更神秘的话)。
此外,大多数大学都教授FP,许多甚至将其作为第一门编程课程。