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


当前回答

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键来维护应用程序状态,并维护有状态命令语言的抽象(有时相当容易泄漏)。

而且,应用程序越无状态,就越容易进行并行处理。如果你的网站很受欢迎,这对网络来说非常重要。向站点添加更多硬件以获得更好的性能并不总是那么简单。

其他回答

f#可能会流行起来,因为微软正在推动它。

Pro:

f#将成为Visual Studio下一个版本的一部分 微软建立社区已经有一段时间了——布道者、书籍、与知名客户合作的顾问,以及在微软会议上的大量曝光。 f#是第一个类。net语言,也是第一个具有强大基础的函数式语言(我不是说Lisp, Haskell, Erlang, Scala, OCaml没有很多库,他们只是没有。net那么完整) 强烈支持并行

合同:

即使你精通c#和。net, f#也很难上手——至少对我来说是这样的:( 可能很难找到好的f#开发人员

所以,我给f# 50:50的机会变得重要。其他函数式语言在不久的将来也不会出现。

我认为你问题的答案更多地在于“工作的正确工具”这句话,而不是最热门的东西。总会有热门的新技术,也总会有人扑上去。

函数式语言已经出现了一段时间,只是现在它们得到了更多的报道。

我一直对“下一件大事”持怀疑态度。很多时候,下一个大事件纯粹是历史的偶然,无论技术好坏,它都在正确的时间出现在正确的地点。例如: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.

讨论中忽略的一点是,最好的类型系统存在于当代FP语言中。更重要的是,编译器可以自动推断所有(或至少大部分)类型。

有趣的是,在编程Java时,有一半的时间花在编写类型名上,然而Java到目前为止还不是类型安全的。虽然你可能从来没有在Haskell程序中写过类型(除非作为一种编译器检查的文档),但代码是100%类型安全的。

函数式编程已经存在很长一段时间了,因为LISP是最早拥有编译器的语言之一,而且自从MIT的LISP机器问世以来。这不是一种新的范式(OO更新得多),但主流软件平台倾向于用易于转换为汇编语言的语言编写,它们的api非常倾向于命令式代码(UNIX使用C, Windows使用C, Macintosh使用Pascal和后来的C)。

我认为过去几年的新创新是api的多样性,尤其是在平台api无关紧要的web开发领域。因为你没有直接对Win32 API或POSIX API进行编码,这就给了人们尝试函数式语言的自由。