4 ms·
I think the fact that Rust won't provide inheritance based OOP workflows means that something like swift will always be valuable, especially for application dev
by seanalltogether 4y ago
I think the fact that Rust won't provide inheritance based OOP workflows means that something like swift will always be valuable, especially for application development.
- Gigachad 4y agoWhat is the value provided by inheritance? It was my understanding that this was deliberately excluded from Rust as it's now seen as a bit of an anti pattern mostly inferior to traits.
- sacnoradhq 4y agoNone. It's code organizational syntactic sugar and abstraction that incurs a runtime penalty (vtables). Go ditched OO for similar reasons. Haskell, Erlang, and more get along fine without OO. (OO crested with Smalltalk, Java, Ruby, Python, and JS (more prototypal though). Let's not talk about C++98)
- metaltyphoon 4y agoDon’t trait objects work the same way as vtables (fat pointer)?
- Gigachad 4y agoMonomorphisation solves this. The compiler duplicates functions for every type you use them with in the finished binary.
- seanalltogether 4y agoInheritance is about providing business logic in all downstream inheritors through a super() chain. If you want shared logic in Rust between several implementors of a trait you will probably end up with duplicate code. There are drawbacks to both.
- Gigachad 4y agoYou can solve duplication with macros to implement traits. The Rust way seems to provide the same convenience without the runtime costs.
- seanalltogether 4y agoMacros provide code injection, that's not the same thing. Inheritance allows for overrides so you can have [default super logic]+[custom child logic]. That's only possible in rust with a lot of copy and paste, which can be fragile to maintain long term. Most UI frameworks are built around inheritance to guarantee logic provided by the base view or view group, while allowing for inheritors to mix in custom logic as well