3 ms·
This is it. OOP is about building sub programs with their own state and behaviours, yet implementing a common interface so they can still effectively communicat
by bruce343434 3y ago
This is it. OOP is about building sub programs with their own state and behaviours, yet implementing a common interface so they can still effectively communicate to each other.
If you boil it down to the essence, this means branching logic is encoded via a function pointer. Instead of manually switching to the correct behavior using other branching mechanisms like if or switch.
This is what polymorphism is about. It's pattern matching.
An interface is like an Enum to which you can add entries after it has been defined, and the behaviour for that specific variant naturally then has to be encoded inside the variant itself.
- Gehinnn 3y agoWould it be far fetched to say object oriented programming is inspired by nature/physics? And thus, "more natural" than, let's say, procedural programming. Animals can be modeled nicely with objects/classes. Physical objects do have internal private state and public interfaces. Also in nature, usually, you have multiple similar objects that work the same but have different internal state.
- bruce343434 3y agoThat might have been what Alan Kay was going for with his "cells of an organism" thing, yes. But even if you're not inspired by biology, it might just come up "naturally". Separating your data into structs, then operations on those structs, and not wanting to deal with all kinds of bookkeeping all the time, letting things manage their own - separation of concerns, aka single responsibility principle. I think automatic memory management might be a big example of this. Who wants to bother with this malloc/free stuff all the time? Who wants to keep track of ownership everywhere? Instead, have a dedicated subsystem handle it. That allows a higher signal to noise ratio in all the rest of the code that would otherwise be polluted with malloc/free. It also removes the entire class of bugs that can happen when you inevitably forget either of those. But having memory management in and of itself isn't "OOP". It's just an example of one of the principles that people tout when they talk of "OOP". Those principles can and do apply broadly. Was Alan Kay thinking of all this? I really don't know. All I know is that the dude digs biology.
- meheleventyone 3y agoI think more that messaging was the fundamental part. Modularization and composition is pretty common in most paradigms. I actually looked this up the other day for a different comment but this is Alan Kay's own words on the subject: https://lists.squeakfoundation.org/pipermail/squeak-dev/1998-October/017019.html https://lists.squeakfoundation.org/pipermail/squeak-dev/1998... It's a concept I really like and use quite a bit in game development at the inter/intra-entity communication level even if below that I'd pick a more performant substrate.
- kragen 3y agothis is an excellent essay; thank you for finding the link
- igouy 3y ago"Object-Oriented Software Systems" Byte Magazine 1981 https://archive.org/details/byte-magazine-1981-08/page/n75/mode/1up https://archive.org/details/byte-magazine-1981-08/page/n75/m... "Design Principles Behind Smalltalk" Byte Magazine 1981 https://archive.org/details/byte-magazine-1981-08/page/n299/mode/1up https://archive.org/details/byte-magazine-1981-08/page/n299/...
- mostlylurks 3y ago> OOP is about building sub programs with their own state and behaviours, yet implementing a common interface so they can still effectively communicate to each other. This doesn't seem like a sufficient definition, as closures are also sub programs with their own state and behaviors that implement a common interface (the function signature), and you'd have to stretch the definition of OOP to the point of meaninglessness if that would be sufficient to qualify as OOP.