我在这里看到很多关于函数式语言的讨论。为什么你要使用传统语言而不是传统语言呢?他们在哪些方面做得更好?他们更不擅长什么?理想的函数式编程应用程序是什么?
当前回答
我一直对“下一件大事”持怀疑态度。很多时候,下一个大事件纯粹是历史的偶然,无论技术好坏,它都在正确的时间出现在正确的地点。例如: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.
其他回答
f#可能会流行起来,因为微软正在推动它。
Pro:
f#将成为Visual Studio下一个版本的一部分 微软建立社区已经有一段时间了——布道者、书籍、与知名客户合作的顾问,以及在微软会议上的大量曝光。 f#是第一个类。net语言,也是第一个具有强大基础的函数式语言(我不是说Lisp, Haskell, Erlang, Scala, OCaml没有很多库,他们只是没有。net那么完整) 强烈支持并行
合同:
即使你精通c#和。net, f#也很难上手——至少对我来说是这样的:( 可能很难找到好的f#开发人员
所以,我给f# 50:50的机会变得重要。其他函数式语言在不久的将来也不会出现。
大学里并没有真正教授(或者现在有吗?)
我不知道现在的情况,但在90年代中期,我在计算机科学课程中学习了米兰达语言和Lisp语言。尽管从那以后没有使用纯函数语言,但它影响了我解决问题的方式。
大多数应用程序都足够简单,可以用正常的面向对象方法解决
在90年代中期的CS课程中,面向对象(使用Eiffel教授)的教学与函数式编程相当。两者在当时都是非主流的。面向对象现在可能是“正常”的,但过去并非如此。
我很有兴趣看看f#是否是将FP推向主流的东西。
我很难想象纯函数式语言会成为当今的通用语言,其中的原因我就不赘述了(因为它们是煽风点火的材料)。也就是说,无论哪种语言(如果允许的话),函数式编程都能带来好处。对我来说,更容易测试我的代码。我经常和数据库打交道……我倾向于:
编写一个函数来获取数据、操作数据并返回数据 编写一个非常简单的包装器,调用数据库,然后返回通过函数传递该数据的结果
这样做允许我为操作函数编写单元测试,而不需要创建模拟之类的东西。
我确实认为纯函数式语言非常有趣……我只是觉得对我来说重要的是我们能从他们身上学到什么,而不是我们能用他们做什么。
I don't know whether it will catch on or not, but from my investigations, a functional language is almost certainly worth learning, and will make you a better programmer. Just understanding referential transparency makes a lot of design decisions so much easier- and the resulting programs much easier to reason about. Basically, if you run into a problem, then it tends to only be a problem with the output of a single function, rather than a problem with an inconsistant state, which could have been caused by any of the hundreds of classes/methods/functions in an imparative language with side effects.
FP的无状态本质更自然地映射到web的无状态本质,因此函数式语言更容易让自己更优雅,更RESTFUL的web应用程序。与JAVA和. net框架形成鲜明对比的是,它们需要在本质上无状态的功能平台(如web)上使用VIEWSTATE和SESSION键来维护应用程序状态,并维护有状态命令语言的抽象(有时相当容易泄漏)。
而且,应用程序越无状态,就越容易进行并行处理。如果你的网站很受欢迎,这对网络来说非常重要。向站点添加更多硬件以获得更好的性能并不总是那么简单。
为什么函数式编程很重要