3 ms·
The article lost credibility with me for the “OO is not about state” section because it misses the point. If all you have are singleton objects with static fun
by mlthoughts2018 8y ago
The article lost credibility with me for the “OO is not about state” section because it misses the point.
If all you have are singleton objects with static functions and no private data attributes, then I agree, but it’s also meaningless because such objects are very sincerely unrelated to anything from OOP. They are just stateless buckets of functions, which is more like a module than an object.
This is actually quite a good way to program in many cases. You can do it in Scala by only defining companion objects and never the actual class that it would correspond to (except for occasional cases where you need case classes or structural typing). You can do this in Python by just writing modules with no classes, and either use primitive data structures (list, set, dict, tuple, etc) for all your data, or else use absolutely minimal namedtuples.
I’d say this way of programming is almost totally FP and has hardly anything but superficial connections to OOP, which I think undermines the author’s point.
You can always claim it’s a semantic difference and different people mean different things with certain words. IMO that’d be disingenuous here. Any type of OOP that just uses objects as buckets of functions with no private data attributes is really just FP.
As soon as you add private data attributes whose values can break referential integrity of the object’s function calls, then it’s game over for FP and you’re in total OOP land.
- thrower123 8y agoI'm not sure I would call what you are describing FP, because I'm old enough to remember when it was procedural programming, and it was a very common pattern among people that didn't quite get the whole OO thing yet when the moved from C or Pascal to Java. The main difference, really, would be whether you just poke at globals, or thread them through.
- dnautics 8y ago> As soon as you add private data attributes whose values can break referential integrity of the object’s function calls function calls, then it’s game over for FP Technically you can do something like this in fp land if you're using the actor model to encapsulate hidden state and erroneous code in a passed lambda does something strange to the hidden state. It's pretty hard to do since most fps with actor model put all of your interfaces to the state right in front of you.
- chriswarbo 8y agoActors are very closely related to OOP, especially the Smalltalk/Self message-passing perspective. The main difference is that message sends to actors are asynchronous whilst objects usually aren't.