i guess the case inheritance is best suited for is deep hierarchy. biggest example that comes to mind is GUI libs.
-
-
- View other replies
-
the question, then, is: how would you rearrange wx or qt to use traits instead?
- View other replies
-
worst case is where each level adds extra behavior to the same method — can't exactly ask each trait for its input on some operation
- View other replies
-
or what if you could? idk what it'd look like but that's the basis of most plugin systems, except they have to reinvent it at runtime
-
.
@eevee On the subject of inheritance: How often do you want to override a method... except you want superclass functionality to "wrap" it? -
.
@eevee How about methods which work "backwards", i.e. instead of child doing "super.method(blah)", the parent does "child.method(blah)"? -
.
@eevee It seems like a really desirable feature that no language that I'm aware of supports -
@oshepherd well you can do that trivially by just making a separate method that the child implements - Show more
-
-
-
@eevee Behavior specialization. otherwise I just use interfaces. This seems to be something Rust gets really correct -
@atweetingtwit can you think of a case where rust's traits and default methods wouldn't work? - View other replies
-
@eevee i'm not sure you can do stuff like dynamic downcasting with traits objects? -
@ben0x539 since i'm making the language i could just say you totally can ;) - View other replies
-
@eevee does the default method encoding of overridable methods break down immediately when you inherit again and override the non-default -
@ben0x539 well in a trait-based system you just can't inherit again...
-
-
-
- View other replies
-
-
@cathodion@glyph well yeah but you can always make any behavior only be implemented once, by writing a function ;) -
-
-
@cathodion@glyph yeah you can get polymorphism with traits. rust is considering inheritance, but again, mostly for tall hierarchies -
- View other replies
-
-
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.
Owen Shepherd
Stiv, Tweet Twit
Insuf Advan
Dustin King