我在这里看到很多关于函数式语言的讨论。为什么你要使用传统语言而不是传统语言呢?他们在哪些方面做得更好?他们更不擅长什么?理想的函数式编程应用程序是什么?
当前回答
OOP要花多长时间才能被普通的公司程序员理解? 我在乌得勒支大学(Utrecht University)学习函数式编程,我想是在1994年,直到最近几年它才开始在“现实世界”流行起来。 没有所谓的“简单应用程序”。: -)
我认为,当我们开始在硬件中添加越来越多的核心时,软件某些关键部分的免费编程(接近)将是必不可少的。给函数式编程多一点时间。在当前和未来的c#版本中,函数式编程将会让那些公司程序员在没有意识到的情况下做好函数式编程的准备……
其他回答
我认为其中一个原因是有些人认为一门语言是否被接受最重要的部分是它有多好。不幸的是,事情很少这么简单。例如,我认为Python被接受的最大因素不是语言本身(尽管这非常重要)。Python如此受欢迎的最大原因是它庞大的标准库和更大的第三方库社区。
像Clojure或f#这样的语言可能是这个规则的例外,因为它们是构建在JVM/CLR之上的。因此,我没有答案。
大多数应用程序都足够简单,可以用正常的面向对象方法解决
OO的方式并不总是“正常的”。这个十年的标准是上个十年的边缘化概念。 函数式编程是数学。Paul Graham谈Lisp(用函数式编程取代Lisp):
简单解释一下 20世纪50年代的语言并没有过时 不是技术而是数学,而且 数学不会过时。正确的 Lisp不是20世纪50年代的东西 硬件,但是,比如说,快速排序 算法,是在 1960年,现在仍然是最快的 通用的排序。
一些想法:
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年内不会出现反弹(一如既往)。然而,朝着计划生育的趋势是有好处的,值得关注。
你最近有关注编程语言的发展吗?所有主流编程语言的每一个新版本似乎都从函数式编程中借用了越来越多的特性。
Closures, anonymous functions, passing and returning functions as values used to be exotic features known only to Lisp and ML hackers. But gradually, C#, Delphi, Python, Perl, Javascript, have added support for closures. Its not possible for any up-and-coming language to be taken seriously without closures. Several languages, notably Python, C#, and Ruby have native support for list comprehensions and list generators. ML pioneered generic programming in 1973, but support for generics ("parametric polymorphism") has only become an industry standard in the last 5 years or so. If I remember correctly, Fortran supported generics in 2003, followed by Java 2004, C# in 2005, Delphi in 2008. (I know C++ has supported templates since 1979, but 90% of discussions on C++'s STL start with "here there be demons".)
是什么让这些功能吸引程序员?这应该是显而易见的:它帮助程序员编写更短的代码。如果想要保持竞争力,未来所有的语言都将至少支持闭包。在这方面,函数式编程已经成为主流。
大多数应用程序都很简单 可以用正常的面向对象方法解决
谁说不能用函数式编程来处理简单的事情?并不是每个函数程序都需要是编译器、定理证明器或大型并行通信交换机。除了更复杂的项目外,我还经常使用f#来编写临时脚本。
我认为函数式编程语言成为“下一个大事件”的最大理由是,在未来,多核处理器将成为标准。程序员将不得不利用这一点,而函数式编程为构建顶级并发软件提供了极好的可能性。
附注:当我在波士顿大学(1998 - 02)读大学时,我们花了一个学期学习Scheme,它是LISP的近亲。我们刚开始学的时候,我都想把头发扯下来。课程结束时,一切都变得很自然了。