我在这里看到很多关于函数式语言的讨论。为什么你要使用传统语言而不是传统语言呢?他们在哪些方面做得更好?他们更不擅长什么?理想的函数式编程应用程序是什么?
当前回答
讨论中忽略的一点是,最好的类型系统存在于当代FP语言中。更重要的是,编译器可以自动推断所有(或至少大部分)类型。
有趣的是,在编程Java时,有一半的时间花在编写类型名上,然而Java到目前为止还不是类型安全的。虽然你可能从来没有在Haskell程序中写过类型(除非作为一种编译器检查的文档),但代码是100%类型安全的。
其他回答
一些想法:
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年内不会出现反弹(一如既往)。然而,朝着计划生育的趋势是有好处的,值得关注。
我要指出的是,你所说的关于函数式语言的一切,大约20年前,大多数人都在谈论面向对象语言。在那时候,OO是很常见的:
* The average corporate programmer, e.g. most of the people I work with, will not understand it and most work environments will not let you program in it
* It's not really taught at universities (or is it nowadays?)
* Most applications are simple enough to be solved in normal IMPERATIVE ways
改变必须来自某个地方。无论接受过早期技术培训的人是否认为变革没有必要,有意义的重要变革都会发生。尽管当时有很多人反对,但你认为向OO的转变是好的吗?
我没有看到任何人在这里提到房间里的大象,所以我认为这取决于我:)
JavaScript是一种函数式语言。随着越来越多的人使用JS做更高级的事情,特别是利用jQuery、Dojo和其他框架的优点,FP将通过web开发人员的后门引入。
与闭包结合使用,FP使JS代码非常轻便,但仍然可读。
欢呼, PS
哇,这是一个有趣的讨论。我对此有自己的看法:
FP使一些任务相对简单(与非FP语言相比)。 非FP语言已经开始从FP中汲取思想,所以我怀疑这种趋势会继续下去,我们将看到更多的合并,这将帮助人们更容易地过渡到FP。
Slava Akhmechet写了一篇很棒的文章,叫做《函数式编程》(顺便说一下,正是这篇文章让我开始接触FP)。在FP带来的好处中,他非常规地强调了以下几点(我认为这有助于软件工程师的吸引力):
单元测试 调试 并发性 热码部署 机器辅助证明与优化
然后继续讨论FP中更多传统讨论的方面的优点,如高阶函数、咖喱、惰性求值、优化、抽象控制结构(尽管没有讨论单子)、无限数据结构、严格性、延续、模式匹配、闭包等。
强烈推荐!