我在这里看到很多关于函数式语言的讨论。为什么你要使用传统语言而不是传统语言呢?他们在哪些方面做得更好?他们更不擅长什么?理想的函数式编程应用程序是什么?
当前回答
一些想法:
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年内不会出现反弹(一如既往)。然而,朝着计划生育的趋势是有好处的,值得关注。
其他回答
我没有看到任何人在这里提到房间里的大象,所以我认为这取决于我:)
JavaScript是一种函数式语言。随着越来越多的人使用JS做更高级的事情,特别是利用jQuery、Dojo和其他框架的优点,FP将通过web开发人员的后门引入。
与闭包结合使用,FP使JS代码非常轻便,但仍然可读。
欢呼, PS
我个人认为,对于分布式系统和多线程/并行编程,函数式编程将很快取得突破。只要它通过编程库与现有的OOP范式集成。所以…在我看来,纯功能的方法仍将停留在学术上。
Slava Akhmechet写了一篇很棒的文章,叫做《函数式编程》(顺便说一下,正是这篇文章让我开始接触FP)。在FP带来的好处中,他非常规地强调了以下几点(我认为这有助于软件工程师的吸引力):
单元测试 调试 并发性 热码部署 机器辅助证明与优化
然后继续讨论FP中更多传统讨论的方面的优点,如高阶函数、咖喱、惰性求值、优化、抽象控制结构(尽管没有讨论单子)、无限数据结构、严格性、延续、模式匹配、闭包等。
强烈推荐!
函数式编程将很可能成为工程师和科学家用来解决他们所面临的问题的工具。它不会像早期的语言那样占领世界。然而,最难打败的产品是Excel,如果我是一名工程师,需要做计算,Excel是很棒的。
However, F# is going to be another source and will likely fill design needs by the non-Computer Scientists. Let's face it, Computer Scientists have done a great job of creating a WHOLE new way of doing things. Object Oriented Programming is GREAT. But sometimes you just need a way to solve an equation, get a solution and graph it. That's it. Then a language like F# fills the bill. Or maybe you want to build a finite state machine, F# again could be one of the solutions, but then C could be a solution as well.
但是当涉及到并行处理时,Excel大放异彩,f#也会及时出现。但是要以友好的方式,F#= friendly。
我不认为函数式语言能解决任何问题,这只是管理层试图推销的一种炒作,记住唯一的事实:
没有灵丹妙药。
其余的都是胡扯,他们还说OO会解决我们的问题,Web服务会解决我们的问题,Xml会解决我们的问题,但最后上面的真理适用了,一切都失败了。而且,20年后,谁说我们还会使用二进制计算机呢?为什么不是量子计算机呢?没有人能预测未来,至少在这个星球上不能。(这是第二条真理)