3 ms·
Sibling comment also says "has interface inheritance with pretty much the same syntax", but this is another case where people see the same ASCII char and think
by pornel 3y ago
Sibling comment also says "has interface inheritance with pretty much the same syntax", but this is another case where people see the same ASCII char and think it's the same feature, when it's so different.
The A:B syntax is not inheritance, but a syntax sugar for 'A where Self:B' bound.
The result is these remain separate traits without support for subtyping. dyn trait A:B can't be used where B is required, unless you have access to the concrete type and make a new vtable for B from scratch. There's WIP to fix that, but not here yet.
The auto traits that look like subtyping are for built-in marker traits only.
Lack of data inheritance is painful. There's no support for fields in traits. Getters/setters are problematic due to borrowing all of self instead of just the field.
Traits can't have private or protected methods.
Traits aren't inherent to the types, so you have to import both the type and the trait to use it. It's messy and makes interface docs confusingly fragmented.
So Rust really really isn't an OOP language, even though you can put together an awkward-to-use imitation from a few ill-fitting features — but they use the same sigils as OO in C++!
- pjmlp 3y agoRust is OOP, regardless how many try to sell it as not, there are many ways to skin a cat. You can enjoy my Rust version of Raytracing on one weekend, then again maybe not. Just like being an FP language doesn't mean does it like Haskell. Many of which even predate Haskell's birthdate. Plenty of ACM, SIGPLAN, IEEE, and EUROCOOP papers on the matter, including a few ones from a certain Simon Peyton Jones.