混合面向对象和函数式编程 [英] Mixing object-oriented and functional programming

查看:110
本文介绍了混合面向对象和函数式编程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可以使用哪些语言来促进面向对象和函数式编程?我知道任何支持第一类函数的语言都可以被认为是功能性的,但是我正在寻找一种针对这两种编码风格的语法。



使用这样的语言,我想象的是将所有状态变化隔离为一部分代码,并让程序的其余部分完全实用。只是想到这让我流口水(调试天堂!)。

到目前为止,我已经发现 Scala 虽然我只听说过它(而且看起来很神奇)。在这种混合风格模式中,有没有什么大的竞争者? 最着名的是 OCaml F#(它可以被隐约地描述为.NET的OCaml)。



还有许多其他多范式语言,如 Oz ,但它们大多具有教学价值。相比之下,OCaml非常实用。它几乎和C一样快,几乎和Haskell一样美丽:)



像Python和Ruby这样流行的脚本语言也可以让你用功能风格进行编程。然而,他们没有提供经典功能语言(以及OCaml)具有的最强有力的设施之一:模式匹配(不要误认为是正则表达式)。


What languages are available that promote both object-oriented and functional programming? I know that any language that supports first-class functions can be considered functional, but I'm looking for a syntax that's specifically targeted for both coding styles.

Using such a language, I'm imagining isolating all state changes to a single portion of code and having the rest of the program be purely functional. Just thinking of it makes me drool (debugging heaven!).

So far I've discovered Scala although I've only just heard of it (and it looks amazing). Are there any big contenders in this "mixed style" paradigm?

解决方案

The best known are OCaml and F# (which can be vaguely described as OCaml for .NET).

There are many other multi-paradigm languages, like Oz, but they have mostly pedagogical value. By contrast, OCaml is very practical. It's almost as fast as C and almost as beautiful as Haskell :)

The popular scripting languages like Python and Ruby let you program in functional style as well. However, they don't provide one of the strongest facilities that "classical" functional languages (as well as OCaml) have: pattern matching (don't mistake it for regexp).

这篇关于混合面向对象和函数式编程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆