4 ms·
IMO they just expose more of how OOP really works, giving you flexibility. Take Rust. Just because I like their pragmatic approach. They represent objects as s
by nullwasamistake 7y ago
IMO they just expose more of how OOP really works, giving you flexibility.
Take Rust. Just because I like their pragmatic approach. They represent objects as structs with functions attached that have access to the struct data. In C++, Java, etc this is roughly how objects actually work underneath.
They eliminate inheritance, replacing it with interfaces. Exposing the objects for what they really are, structs with functions attached, makes this strategy easier.
Traditional OOP, especially with multiple inheritance, tends to encourage nested objects (structs) that become hard to reason about.
Another related innovation has been structural typing. Typescript is great with this. Essentially, if you have two "objects" with the same fields, you can assign them to eachother freely. Typescript doesn't care if they actually inherit from eachother. If the interface signatures are compatible (matching fields, matching types), they can be freely used in eachothers place. This is great for constructing anonymous objects to pass off without all the cruft, basically just Json fields.
TLDR: newer languages decided that if two objects look like ducks they are both ducks, even if you decide to call one something else. Because who really cares what you name your ducks or which ducks they inherit from. This breaks from traditional OOP by loosening the rules of inheritance, but so far it's been a boon for productivity (for me at least)
- Skinney 7y agoI disagree with it being OO when it doesn’t have inheritance. No classes or class hierarkies, no passing things along to children. Seems very different than what those who invented OO had in mind. Structs with functions attached is easy, and not entirely uncommon in procedural and even functional languages.
- spacemanmatt 7y agoInterfaces are inheritance, just without code. But interfaces definitely serve at least one role of an abstract base class.
- Skinney 7y agoMaybe. But then even FP languages are considered OOP, as most of those languages have records and interfaces.
- nullwasamistake 7y agoYes I agree. Once you have interfaces with default implementations especially, you have non-nested OOP
- apta 7y ago> They eliminate inheritance, replacing it with interfaces. Exposing the objects for what they really are, structs with functions attached, makes this strategy easier. I don't see how this is not already achievable in Java or C#. No one is forcing you to use inheritance. And when you really need it, it's there for you to use instead of jumping through hoops.
- nullwasamistake 7y agoThat's basically true. Languages that use interfaces with structural typing are significantly easier to work with though. You can "implement" an interface implicitly by just having matching fields
- apta 7y agoThis means you can't use interfaces as tags, which is a very important feature (e.g. see how it's used in Rust). It also means that you have several different types implementing your interface "by coincidence", making it difficult to use an IDE to find out the types of interest, not to mention what sorts of bugs might result because of this. There are better solutions like what Kotlin and Scala use (and potentially C# in a future version).
- nullwasamistake 7y agoJS solves the tagging issue using "symbols". They're extremely weird at first look but they're basically around for that reason.
- dllthomas 7y ago> Because who really cares what you name your ducks or which ducks they inherit from. Who cares if it's an employee or a gun, as long as I can fire it.
- nullwasamistake 7y agoUnderrated comment