4 ms·
I believe Rust wants inheritance primarily for Servo, because the DOM is defined in terms of inheritance.
by eridius 13y ago
I believe Rust wants inheritance primarily for Servo, because the DOM is defined in terms of inheritance.
- pcwalton 13y agoRight. Idiomatic Rust prefers composition over inheritance.
- zanny 13y agoEvery language in the universe prefers composition over inheritance =P
- seanmcdirmid 13y agoNot very true. Some languages prefer inheritance to express is-a relationships and composition to express has-a relationships. Some languages try to shoe horn is-a into being equivalent to has-a, but they usually have trouble expressing non-structural subtyping.
- banachtarski 13y agoThe ones that don't blossom into interface factories which make factory adapters of abstract factories. (I'm looking at you, Java)
- V-2 13y agoFor the lack of a nail, throw new HorseshoeNailNotFoundException("no nails!"); For the lack of a horseshoe, EquestrianDoctor.getLocalInstance().getHorseDispatcher().shoot(); (...) http://steve-yegge.blogspot.com/2006/03/execution-in-kingdom-of-nouns.html http://steve-yegge.blogspot.com/2006/03/execution-in-kingdom...
- jeltz 13y agoIf that is the only use case I would rather want another solution to keep the language minimal. Just like the garbage collection was moved to a library.
- dbaupp 13y agoI think that the core team thought about this long and hard, but it was decided that there was no other solution. A virtual method call to look up some property shared by all the DOM nodes was just too expensive: a constant offset field look up is far far faster.
- pcwalton 13y agoCan't really do it. I tried. The type checker just plain has to know about inheritance for it to work and be safe. The good news is that's an extremely constrained sort of inheritance, very unlike traditional OO in that it doesn't have base classes--it's just a special extension to the trait (typeclass) system that allows you to require that structs begin with a certain set of fields. In fact, I don't even call it inheritance these days--I prefer the name "structural constraints".
- thirsteh 13y agoI think this is a good idea. It seems similar to Go's embedding: http://golang.org/doc/effective_go.html#embedding http://golang.org/doc/effective_go.html#embedding