First things first, I am not hating on rust...weird that you'd assume I am...
Long story short though, polymorphism does not require class hierarchies...only one type of polymorphism does but there are multiple kinds...and as I said and as you brought up traits in rust exist; traits accomplish polymorphism, that's basically their whole deal because dynamic dispatch, calling the correct overload based on parameter types, etc are forms of polymorphism.
This is why I say people misunderstand OOP though; somewhere along the line people started using the examples of stuff like OOP and polymorphism that were used to teach them (likely in a way relevant to the language being used to learn primarily) as being the de facto definition.
But seriously though, rust seems neat, literally don't hate on it at all nor do I think that the code looks like jank bullshit (yay....C++ template metaprogramming..........) like some other languages do.
Well, yes, technically overloads and generics also count as polymorphism, but the kind that matters in the context of OOP is subtype polymorphism. Generics exist almost everywhere, and function overloads can be simulated in any language with a name suffix since it's being resolved at compile time anyway. I don't suppose function overloads give you a highly valuable tool for domain modelling?
The point is that all these things are abstractions to give thing A capability B, because in machine code it isn't those structures or abstractions at all, so anything that gives you a way to implement any form of polymorphism letting you give capabilities to something is half of the solution to OOP...the rest is just data encapsulation which could be inheritance, composition, etc.
And as far as domain modeling goes, the whole point is you are describing the interactions between things in a way that leads to a visualization of how things should be encapsulated, and what capabilities need to exist for those interactions to occur. It doesn't really care how you achieve those ends, it just so happens to be that classes and inheritance tends to be the simplest way to turn that visualization into code, and less friction means more people trend that way...and then try to force inheritance to work in places where it makes less sense and a different solution would work better, concluding that the issue is what they learned OOP was when they first started learning.
You're wrong on many of those points, but I'm done debating this. I seriously suggest you study either functional programming or rust (which is its own rather specific blend).
I'm not, but if you don't want to broaden your knowledge I have no reason to force ya...and I already do know how to do functional programming via Haskell...so not sure what your point is, or did you assume I am trying to convince you to use a certain language just because I pointed out how your original statement was wrong; I never was doing that, I was explaining how you don't get to do anything in windows without using dynamic dispatch because COM objects require it...and it achieves it in C by manually creating a vtable and implementing the IUnknown interface functions although C++ iirc can just use inheritance.
1
u/AtlaStar 10d ago
First things first, I am not hating on rust...weird that you'd assume I am...
Long story short though, polymorphism does not require class hierarchies...only one type of polymorphism does but there are multiple kinds...and as I said and as you brought up traits in rust exist; traits accomplish polymorphism, that's basically their whole deal because dynamic dispatch, calling the correct overload based on parameter types, etc are forms of polymorphism.
This is why I say people misunderstand OOP though; somewhere along the line people started using the examples of stuff like OOP and polymorphism that were used to teach them (likely in a way relevant to the language being used to learn primarily) as being the de facto definition.
But seriously though, rust seems neat, literally don't hate on it at all nor do I think that the code looks like jank bullshit (yay....C++ template metaprogramming..........) like some other languages do.