5 ms·
> his combination of data and code in a strict hierarchy means that all data access patterns are baked into this dependency tree I believe OOP is really good a
by dgb23 6y ago
> his combination of data and code in a strict hierarchy means that all data access patterns are baked into this dependency tree
I believe OOP is really good at modelling state and really bad at modelling data.
With state (and side-effects modeled by state machines) you want a well-defined interface, messages, local retention and so on. This way you get the benefit of reasoning about state in a constrained manner both as the caller and the callee.
For example it makes sense to model Mario as a state-machine that receives messages from game-pad (pressed buttons) and collision events. Note that this is a conceptual, high level kind of modelling and not a concrete, structural one.
But data is about something. There is data about Mario at any given point in time: his physical dimensions, his velocity, consumed power ups and so on.
This is where OOP makes no sense at all. Reading and transforming data should be universal/uniform rather than guarded by idiosyncratic getters, setters and so on.
This is why SQL, JSON, XML, HTML, Unix filters, AWK, Functional Programming etc. are so powerful. These technologies provide/enable a uniform/universal way of reading data and composing transformations.
(As a side-note: I consider state that never leaks as an implementation detail, usually for performance)
- airstrike 6y ago> his physical dimensions, his velocity, consumed power ups and so on. Aren't his physical dimensions just attributes of the Mario instance (or class definition)? Similarly, his velocity, consumed power ups and so on can all be attributes of the stage he's in. His extra lives can be an attribute of this current game session.
- dgb23 6y agoMario‘s attributes are a composite of different measurements that are partly needed in different contexts of the simulation. They are just data. And like any data we should be able to query it without knowing Mario‘s special access pattern.
- pjmlp 6y agoUsually that just shows the lack of understanding of how to use OOP, and what should be proper classes, what should be interfaces or categories, depending on the language.
- dgb23 6y agoThats the point. There shouldn’t be any deeper understanding necessary at all to represent the simplest and most prevalent case conveniently and uniformly. Many of the core principles of OO make sense in a stateful context, that doesn’t automatically make them a good fit for data as well.
- pjmlp 6y agoSame argument can be done for FP or ADT (abstract data types). Some people like to seat at the keyboard and code away, but don't expect stellar results without taking the effort to learn best practices, by reading books and such.
- RobertKerans 6y agoWell, quite, but that doesn't obviate the point. What you're describing has an exact corollary: "Saying FP is not as good at handling state as OOP just shows a lack of understanding of FP, of structures such as the state monad." Yes, using strict patterns to deal with the weak points of the overall paradigm is absolutely fine, but it's patching over cracks rather than using the best tool for the job. OOP is very good at handling state but less good at pipelining data, FP is very good at pipelining data but less good at handling state.
- pjmlp 6y agoExcept that most modern languages are multiple paradigm, again it reflects more lack of effort into learning best practices than anything else.
- dgb23 6y agoLanguages being multi paradigm reflects that people want to use the best tool for the job, not lack of learning. This stems from favoring pragmatism over style. The conclusions about OOP and FP having their specific trade-offs are not made by people who don't learn, but by people who did and then applied different methods and see their trade-offs.