3 ms·
If you aren't going to use polymorphism to vary behavior, but depend on conditionals, what do you use classes for? Just for hierarchical data encapsulation?
by laserlight 4y ago
If you aren't going to use polymorphism to vary behavior, but depend on conditionals, what do you use classes for? Just for hierarchical data encapsulation?
- pkolaczk 4y agoSurprise: I don't use classes. Rust doesn't have them. :P
- laserlight 4y agoSo, you’ve been arguing for using switch statements, instead of Clean Code’s suggestion of using object-oriented polymorphism, in a context where polymorphism doesn’t exist?
- pkolaczk 4y agoNot at all. Not having classes is not the same as not having polymorphism. Rust supports polymorphism just fine (and one could argue its support for polymorphism is actually much more advanced than that of Java's; but that's not enough reason to use it everywhere).
- whstl 4y agoThe greatest trick OOP ever pulled was convincing the world that polymorphism didn't exist outside OOP.
- bart_spoon 4y agoHow are structs in Rust any different than classes?
- hdhrufjdi 4y agoBehavior and data is more separated A struct only contains data, however you e.g. can define methods on it or implement traits for it No inheritance.
- bart_spoon 4y agoThey don’t only contain data though, you can define methods as you said. Yes, there is no-inheritance, but they contain data, maintain state, and allow for defined methods. 90% of the time people are talking about classes, they are talking about that.
- goto11 4y agoI use multiple languages and I always consider the context of programming advice. I recommend a broadened perspective. In general I would rather maintain code by someone who have read Clean Code than by someone who considers it beneath them because they are too elite.
- dsego 4y agoAfaik, data-oriented approach doesn't use classes to encapsulate behavior.