2 ms·
OO was created for a reason. Before OO, you had these data structures, and they got passed around between functions. Well-designed data structures were not ju
by AnimalMuppet 2y ago
OO was created for a reason.
Before OO, you had these data structures, and they got passed around between functions. Well-designed data structures were not just a random collection of items - they had a relationship between the elements. And you kept finding structures that were in an invalid state - the relationship among the elements had been broken. Well, who did that? You couldn't tell. It could have been any function anywhere in the code that took the structure.
With OO, you could have a very small set of functions that could change the structure. If the constraints got broken, you had a very small footprint to look at to see how it could have happened. That was the OO advantage.
And this advantage did not go away with multiple programmers. In fact, it increased. If you had a class that you "owned", some other new (or incompetent) programmer could not break your code without changing that class's code. You didn't have to rely on everyone else always doing the right thing with your structure.
Note that this advantage is orthogonal to inheritance vs. non-inheritance.
- bhouston 2y ago> And you kept finding structures that were in an invalid state - the relationship among the elements had been broken. Which is why functions should have typed arguments and results. :)
- sirwhinesalot 2y agoEncapsulation is not solely an OOP idea, it's also a modular programming thing. That many languages lack proper module support is a whole other matter. But there are many advantages to doing encapsulation through modules over classes, if nothing else being able to have the internal functions organized in different files, and having "internal"/"external" functions have the exact same syntax without needing hacks like extension methods.
- DeathArrow 2y ago> OO was created for a reason. Likewise, null was created for a reason. Not a good reason.