Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You can implement functions as objects and objects as collections of functions, so there is clearly some relationship between the two concepts.</p> <blockquote> <p>FP encourages immutability and purity as much as possible</p> </blockquote> <p>You are talking about <em>purely</em> functional programming.</p> <blockquote> <p>while OO seems built for state and mutation </p> </blockquote> <p>There is no requirement for objects to be mutable. I would say that objects and mutation were orthogonal concepts. For example, the OCaml programming language provides a syntax for purely functional object update.</p> <blockquote> <p>A language like Scala makes it easy to do OO and FP both</p> </blockquote> <p>Not really. The lack of tail call optimization means that the majority of idiomatic purely functional code will stack overflow in Scala because it leaks stack frames. For example, <a href="http://en.wikipedia.org/wiki/Continuation-passing_style#CPS_and_tail_calls" rel="noreferrer">continuation passing style</a> (CPS) and all of the techniques described in the paper <a href="http://www.lfcs.inf.ed.ac.uk/reports/97/ECS-LFCS-97-375/ECS-LFCS-97-375.pdf" rel="noreferrer">That about wraps it up</a> by Bruce McAdam. There is no easy way to fix that because the JVM itself is incapable of tail call optimization.</p> <p>Regarding the orthogonality of purely functional programming and object oriented programming, I would say that they are at least close to being orthogonal simply because purely functional programming deals only with programs in the small (e.g. higher order functions) whereas object oriented programming deals with the large-scale structuring of programs. This is why functional programming languages usually provide some other mechanism for large-scale structuring, e.g. the higher-order module systems of Standard ML and OCaml, or CLOS for Common Lisp or typeclasses for Haskell.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload