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


当前回答

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

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

其他回答

一些想法:

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年内不会出现反弹(一如既往)。然而,朝着计划生育的趋势是有好处的,值得关注。

实际上,在阅读了《黑客与画家》之后,我正在学习LISP,我相信我会从LISP中学到一些东西,这将使我更好地理解我所编程的其他东西。现在我不认为我会在我的日常生活中使用LISP,只是因为有人在1995年创建了一个网站,成为雅虎商店。所以无论如何这是一个双赢(如果它流行起来,我赢了,如果没有,我得到了更多关于如何编程和如何工作的观点)

现在…关于另一个有点相关的问题,我认为明年32核处理器到来后编程会发生很大变化吗?是的,我不知道它是否会是函数式编程,但是…我很确定会有一些不同的东西!

呃,很抱歉,我是一个学究,但它已经流行起来了——我们称之为Excel。

http://research.microsoft.com/en-us/um/people/simonpj/papers/excel/

在计算机上运行的绝大多数程序都是用Excel或其众多流行克隆版本之一编写的。

(有许多程序运行多次,而用Excel编写的程序往往不是其中之一-大多数Excel程序都有1个运行实例)

大学里并没有真正教授(或者现在有吗?)

我不知道现在的情况,但在90年代中期,我在计算机科学课程中学习了米兰达语言和Lisp语言。尽管从那以后没有使用纯函数语言,但它影响了我解决问题的方式。

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

在90年代中期的CS课程中,面向对象(使用Eiffel教授)的教学与函数式编程相当。两者在当时都是非主流的。面向对象现在可能是“正常”的,但过去并非如此。

我很有兴趣看看f#是否是将FP推向主流的东西。

因为FP在生产力、可靠性和可维护性方面有显著的好处。多核可能是一个杀手级应用程序,最终让大公司在大量遗留代码的情况下转换。此外,即使是像c#这样的大型商业语言,也因为多核问题而呈现出一种独特的函数风格——副作用根本不适合并发性和并行性。

我不认为“普通”程序员不能理解它。他们会的,就像他们最终理解了面向对象编程一样(它同样神秘和怪异,如果不是更神秘的话)。

此外,大多数大学都教授FP,许多甚至将其作为第一门编程课程。