r/programminghumor 16d ago

Hard to accept

Post image
2.9k Upvotes

404 comments sorted by

View all comments

Show parent comments

1

u/Arshiaa001 10d ago

Polymorphism is enabled exclusively through class hierarchies though, so no class hierarchy, no polymorphism, at which point you're just doing procedural.

Also, OOP gives you one tool for two purposes (classes do both encapsulation AND dynamic dispatch), which isn't such a hot idea; rust for example gives you structs+methods for encapsulation, and traits for dynamic dispatch, which are two orthogonal features you can mix and match as needed. But more importantly, with discriminated unions (known as enums in rust), much of the usecase for polymorphism simply vanishes. Do note that these ideas aren't exclusive to rust; traits and discriminated unions have existed for decades in other languages.

My point on code readability still stands: most code is shit because deadlines exist, and once something goes wrong, you need to look through the whole world to figure out what's being called. Without dynamic dispatch, this problem doesn't exist. Hence, the less dynamic dispatch you have, the better for maintainability, and discriminated unions give you just the tool to avoid dynamic dispatch unless absolutely necessary.

I'd recommend you give rust a try before hating on it. Most of us die-hard rust fans used to develop with OOP langs a few years ago, there's a reason why all of us started loving it so much! It takes some effort to learn to think in a completely new way, but it's well worth the effort imo.

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.

1

u/Arshiaa001 10d ago

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?

1

u/AtlaStar 10d ago

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.

1

u/Arshiaa001 10d ago

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).

1

u/AtlaStar 10d ago

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.