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


当前回答

一些想法:

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

其他回答

我同意第一点,但是时代变了。公司会做出回应,即使他们是后期采用者,如果他们看到有一个优势。生活是动态的。

90年代末,他们在斯坦福教授哈斯凯尔和ML。我相信卡内基梅隆大学、麻省理工学院、斯坦福大学和其他一些好学校正在向学生们展示它。

我同意大多数“在网络上公开关系数据库”的应用程序将在很长一段时间内继续这样做。对于这个问题,Java EE、. net、RoR和PHP已经演化出了一些非常好的解决方案。

您发现了一些重要的问题:这可能是其他方法无法轻松解决的问题,而这些方法将促进函数式编程。那是什么?

大规模多核硬件和云计算会推动它们向前发展吗?

函数式语言的一个关键特征是一类函数的概念。其思想是,您可以将函数作为参数传递给其他函数,并将它们作为值返回。

函数式编程包括编写不改变状态的代码。这样做的主要原因是,对函数的连续调用将产生相同的结果。您可以使用任何支持第一类函数的语言编写函数式代码,但有一些语言(如Haskell)不允许更改状态。事实上,你根本不应该产生任何副作用(比如打印文本)——这听起来可能完全没用。

相反,Haskell对IO: monads采用了不同的方法。这些对象包含解释器顶层要执行的所需IO操作。在其他任何层面上,它们都只是系统中的对象。

函数式编程有什么优点?函数式编程允许代码出现错误的可能性更小,因为每个组件都是完全隔离的。此外,使用递归和一级函数允许简单的正确性证明,这通常反映了代码的结构。

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

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

你最近有关注编程语言的发展吗?所有主流编程语言的每一个新版本似乎都从函数式编程中借用了越来越多的特性。

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#来编写临时脚本。

一些想法:

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