关于scala:混合面向对象和函数式编程

Mixing object-oriented and functional programming

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

使用这种语言,我想象将所有状态更改隔离到代码的单个部分,让程序的其余部分完全正常工作。一想到它我就垂涎三尺(调试天堂!).

到目前为止,我已经发现了斯卡拉,尽管我只是听说过它(它看起来很神奇)。在这种"混合式"的模式中,有什么大的竞争者吗?


(P)Javascript:OO and functional.(p)


(P)The best known are ocaml and F%35;(which can be vaguely described as ocaml for net).(p)(P)There are many other multi-paradigm languages,like Oz,but they have mostly educatical value.通过对比,Ocaml是非常实际的。It's almost as fast as C and almost as beautiful as Haskell:(p)(P)The popular scripting languages like Python and Ruby let you program in functional style as well.然而,他们并不提供一个强大的设施,即"classical"functional languages(as well as ocaml)have:pattern matching(don't mistake it for regexp)。(p)


  • 奥坎
  • O'Haskell(and object oriented programming is some possible even in normal haskel)
  • 尼莫
  • Possibly Newlisp

(P)Also,many scripting languages such as Python,Ruby,Lua,etc.Have this capability,but lack many of the nice features of functional languages such as algebraic data types and pattern matching.(p)


哈斯凯尔:纯粹的功能,几乎没有OO,但是继续,潜水吧。D

斯卡拉:OO和FP的完美混合,可能在10年或2年间超过Java作为JVM上的首要语言。我喜欢它,因为它给Java平台带来了功能性的编程,这是非常迫切需要的。

C:对OO的出色支持,以及更多的功能(已经是一流的功能,我们将看到.NET 4带来的改进)

F:.NET语言是专门为实现功能而构建的,而C语言最初是为面向对象的东西而设计的。

python:非常适合OO,但根本不适合FP

javascript:支持一流的函数,但不是专门为fp设计的,比如scala和f。还是比python imho好一点。

为什么要混合OO和FP?作为踏脚石?


(P)Ocaml and F@35;are the most popular languages that mix oop and fp,as far as I know.(p)(P)大多数语言,像鲁比,MIX功能方案在,但一种人民的荷花,甚至不现实。I find languages like that leave a lot to be desired on the syntax front and such.(p)


(P)(c)35;。这是不可或缺的,它可以是手,但它也有功能性的特征。Lambdas,iterators,and linq are all functional.(p)(P)很可能不会有太多人要求净化,但这是对我的工作。(p)


(P)Javascript,Python,and Ruby could be used that way,but scala bumps up a notch by typing the function statcally and working under JVM.(p)


(P)As long as you don't insist on"prity",common Lisp supports all your needs.(p)


(P)你真的会问错问题你的问题是对"oo"和"functional"programming之间的区别的奖励。This distinction isn't interest or relevant.事实上,根据"支持第一类功能"的标准,即使Java也是功能性的。(p)(P)但你用"纯粹的功能"打到了头顶上That's the interesting bit.What languages offer you referential transparency and purity like that?嗯,他们中的大多数,如果你真的很关心。但他们并没有多少人实际上保证你的功能是纯粹的。I can only think of a couple of languages that offer you that.(p)(P)他们中的一个是哈斯凯尔In Haskell,you write programs that are purely functional from beginning to end.side-effects are delegated to a data structure called IO,and state is handled by passing it through pure functions or encapsulating it in monds.So you have your"debging head"where only a small portion of your code interactions with global state and the rest of your program is pure,and purity is enforced by the language.(p)


python、javascript、common lisp、ruby、smalltalk、haskell和ocaml,在我的头顶上。这并不是什么异国情调的组合。


(P)I'm wondering why you are looking for a language that specifically encourages mixing it up rather than just doing it any way with a language that does functional programming and oo programming well?它可以通过Python、Ruby、Perl或类似的翻译语言有效地发展。In addition C based oo languages tend to mix pure c with oo features,for example objective C could easily be written in such a way should you choose.(p)(P)Edit:I have been made aware I'm wrong,I've left this answer here incase someone can learn from my mistake-see comments.(p)


(P)鲁比!In Ruby,everything is an object(even literals),and it also has full functional programming support.(p)