3 ms·
> Rust, not being an object-oriented language, doesn't quite do inheritence like the others. In C++ or Java, subclasses extend superclasses. In Rust, structs im
by shmerl 8y ago
> Rust, not being an object-oriented language, doesn't quite do inheritence like the others. In C++ or Java, subclasses extend superclasses. In Rust, structs implement traits.
I wouldn't say that Rust isn't object oriented. It just takes a different approach to some things. Inheritance isn't really a strictly required feature of the object oriented code design. Many for instance pointed out, that composition is preferable:
https://en.wikipedia.org/wiki/Composition_over_inheritance https://en.wikipedia.org/wiki/Composition_over_inheritance
- millstone 8y agoRust is clearly not object-oriented. It has very minimal support for late binding, and no support for reflection or dynamic libraries. This isn't a critique, it's just a statement of fact. No Rust designer will say they set out to build a new object-oriented language.
- giornogiovanna 8y agoLate binding is the only one of those features commonly associated with object-orientation, and Rust is just as good as C++ on that front.
- shmerl 8y agoC++ has no reflection either. Are you saying it's not object oriented? Rust has late binding (also known as dynamic dispatch). Check trait objects. It's not really any worse than C++ virtual functions which is its form of dynamic dispatch. See https://doc.rust-lang.org/book/ch17-02-trait-objects.html https://doc.rust-lang.org/book/ch17-02-trait-objects.html And Rust has dynamic linking as well: https://doc.rust-lang.org/reference/linkage.html https://doc.rust-lang.org/reference/linkage.html So IMHO Rust has enough features to be used in object oriented fashion.
- oconnor663 8y ago> no support for reflection Rust does have some support for reflection, though it is quite limited. https://doc.rust-lang.org/std/any https://doc.rust-lang.org/std/any
- steveklabnik 8y agoYou can do compile-time reflection, which is very popular.