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?

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.

Sign up to request clarification or add additional context in comments.

4 Comments

By internal function you mean method :)
Do you mean that if a pure function takes an object as parameter, the first thing it should do is to clone it?
By internal function you mean method. Yes.
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.

Your Answer

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.