loading...

Discussion on: OOP vs Functional Programming

Collapse
kant312 profile image
Quentin Delcourt

OOP ♥️ FP
I try to apply both at the same time. Objects should be made immutable and methods should have ideally no side effect, when possible.
The combination is for me an incredible and efficient way to model business logic.
Putting one against the other would be missing out on important concepts, imho.

Collapse
lifelongthinker profile image
Sebastian

But immutable objects are very much the opposite of what OOP is about (encapsulating state), or am I misunderstanding your approach?

I understand the benefits of side-effects-free programming, but those side effects are an inherent part of OOP.

Collapse
kant312 profile image
Quentin Delcourt

To me OOP is not about encapsulating state (although you can do that of course), but rather encapsulating data with behaviour. The fact that these data should be immutable or not depend on the software needs, but I think most of the time we should err on the side of immutability.
TL;DR, I don't think using OOP should force you to have mutability everywhere.

Thread Thread
lifelongthinker profile image
Sebastian

Where's the difference between state and data? I think we are talking about the same thing here.

No, OOP doesn't force you to have mutability. Rather, OOP emerged to satisfy the need for managing mutable state carefully.