Mixing object-oriented and functional programming

前端 未结 12 1730
渐次进展
渐次进展 2020-12-24 01:33

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 fun

相关标签:
12条回答
  • 2020-12-24 02:16

    Javascript: OO and functional.

    0 讨论(0)
  • 2020-12-24 02:16

    Python, javascript, common lisp, ruby, smalltalk, haskell, and ocaml, off the top of my head. It's not really an exotic combination.

    0 讨论(0)
  • 2020-12-24 02:19

    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).

    0 讨论(0)
  • 2020-12-24 02:25

    OCaml and F# are the most popular languages that mix OOP and FP, as far as I know.

    Most languages, like Ruby, mix functional programming in, but a lot of people don't even realize it. I find languages like that leave a lot to be desired on the syntax front and such.

    0 讨论(0)
  • 2020-12-24 02:30

    C#. It's imperative, which can be handy, but also has a lot of functional features. Lambdas, iterators, and LINQ are all functional.

    It probably won't appeal much to purists, but it works for me.

    0 讨论(0)
  • Ruby! In Ruby, everything is an object (even literals), and it also has full functional programming support.

    0 讨论(0)
提交回复
热议问题