0

Scala claims than OO and FP can be combined. I wonder how this can be achieved in practice. I mean object can change, so making them immutable means i have to create a new object whenever something changes right? This doesn't seem too effective to me.

By the way, if i make external reference to an object property from a function, doesn't it hurts referential transparency?

asked Jan 30, 2014 at 16:25

1 Answer 1

1

Don't think of this as one paradigm imposing restrictions on the other but as how can one take the best of both paradigms.

As a simple example:

Objects have functions which can be internal to an object. Now the internal functions can be immutable within an object and those results of a function can be used to change the state of a object.

Thinking at a different level one can use functions to create a library that can be used by objects.

How I like to make the best of both is I tend to make libraries (modules) for the more abstract processing using a functional language and then use OO languages for the layers closer to human and external processing. This is not a hard and fast rule but a guideline from where I start.

answered Jan 31, 2014 at 11:47
4
  • By internal function you mean method :) Commented Mar 28, 2014 at 12:23
  • Do you mean that if a pure function takes an object as parameter, the first thing it should do is to clone it? Commented Mar 28, 2014 at 12:24
  • By internal function you mean method. Yes. Commented Mar 28, 2014 at 15:07
  • Do you mean that if a pure function takes an object as parameter, the first thing it should do is to clone it? No. Think of it like this; the function would pull the object off the stack, change it, then store the result (possibly a modified object) on the stack. Commented Mar 28, 2014 at 15:10

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.