Re:Abstraction without overhead: traits in Rust
by masklinn on Monday May 11, 2015 @04:15PM
(#9527552)
Because trait is a much better word for it: https://en.wikipedia.org/wiki/Trait_(computer_programming)
[ Parent
| on HN ]
Re:Abstraction without overhead: traits in Rust
by EugeneOZ on Monday May 11, 2015 @04:19PM
(#9527574)
So in Rust traits can include full methods bodies, not only signatures?
Re:Abstraction without overhead: traits in Rust
by pcwalton on Monday May 11, 2015 @04:23PM
(#9527595)
Yes. The feature has been proposed for Java too: "defender methods".
Originally I resisted them on the grounds of not being necessary, but they're used all over now. Being able to supply a default implementation is extremely useful.
Re:Abstraction without overhead: traits in Rust
by oldmanjay on Monday May 11, 2015 @04:32PM
(#9527650)
Quick correction: Java 8 does have defender methods.
Re:Abstraction without overhead: traits in Rust
by kzrdude on Monday May 11, 2015 @06:04PM
(#9528152)
default method implementations makes traits behave like mixins, it's very useful (and it is a form of code reuse).
Re:Abstraction without overhead: traits in Rust
by pcwalton on Monday May 11, 2015 @06:41PM
(#9528325)
Totally agreed. I was wrong to resist them :)
Re:Abstraction without overhead: traits in Rust
by EugeneOZ on Monday May 11, 2015 @04:39PM
(#9527702)
Thanks to all for explanations! :) And now I think Traits are traits, but can be used as interfaces too :)
Re:Abstraction without overhead: traits in Rust
by Manishearth on Tuesday May 12, 2015 @06:17AM
(#9530624)
They can also contain associated constants.