我在这里看到很多关于函数式语言的讨论。为什么你要使用传统语言而不是传统语言呢?他们在哪些方面做得更好?他们更不擅长什么?理想的函数式编程应用程序是什么?
当前回答
我一直对“下一件大事”持怀疑态度。很多时候,下一个大事件纯粹是历史的偶然,无论技术好坏,它都在正确的时间出现在正确的地点。例如: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.
其他回答
我很难想象纯函数式语言会成为当今的通用语言,其中的原因我就不赘述了(因为它们是煽风点火的材料)。也就是说,无论哪种语言(如果允许的话),函数式编程都能带来好处。对我来说,更容易测试我的代码。我经常和数据库打交道……我倾向于:
编写一个函数来获取数据、操作数据并返回数据 编写一个非常简单的包装器,调用数据库,然后返回通过函数传递该数据的结果
这样做允许我为操作函数编写单元测试,而不需要创建模拟之类的东西。
我确实认为纯函数式语言非常有趣……我只是觉得对我来说重要的是我们能从他们身上学到什么,而不是我们能用他们做什么。
我认为其中一个原因是有些人认为一门语言是否被接受最重要的部分是它有多好。不幸的是,事情很少这么简单。例如,我认为Python被接受的最大因素不是语言本身(尽管这非常重要)。Python如此受欢迎的最大原因是它庞大的标准库和更大的第三方库社区。
像Clojure或f#这样的语言可能是这个规则的例外,因为它们是构建在JVM/CLR之上的。因此,我没有答案。
我不认为大多数现实的人会认为函数式编程会流行起来(成为像OO那样的主要范式)。毕竟,大多数业务问题都不是漂亮的数学问题,而是用来移动数据并以各种方式显示它们的繁琐的命令式规则,这意味着它不适合纯函数式编程范式(monad的学习曲线远远超过OO)。
对了,函数式编程让编程变得有趣。它会让你欣赏宇宙中潜在数学的简洁表达所蕴含的永恒之美。人们说学习函数式编程会让你成为更好的程序员。当然,这是非常主观的。我个人认为这也不完全正确。
它让你成为一个更有感情的人。
一些想法:
The debate between FP and imperative programming (OO, structured, etc), has been raging since Lisp versus Fortran. I think you pose excellent questions but recognize that they are not especially new. Part of the hoopla over FP is that we seem to be recognizing that concurrency is very difficult, and that locks and other mechanisms in OO (e.g. Java) are just one solution. FP offers a refreshing sea change with ideas such as Actors and the power of stateless computing. To those wrestling with OO, the landscape seems highly appealing. Yes, schools teach FP. In fact, the University of Waterloo and others offer Scheme in first year classes (reference here). Regarding the average programmer, I'm sure that the same arguments were given against C++ back in the early 1990s. And look what happened. If businesses can gain an advantage via a technology, you can bet that people will receive training.
这并不是说这是板上钉钉的事,也不是说在3-5年内不会出现反弹(一如既往)。然而,朝着计划生育的趋势是有好处的,值得关注。
事情朝着功能性的方向发展已经有一段时间了。过去几年的两个很酷的新孩子,Ruby和Python,都比之前的函数语言更接近——以至于一些Lispers开始支持其中一个或另一个,认为“足够接近”。
随着大规模并行硬件给每个人带来了进化的压力——函数式语言是应对这些变化的最佳位置——认为Haskell或f#将成为下一个大事件的飞跃并不像以前那么遥远。