News for hackers. Stuff that matters.
Re:Rust 0.9 released by pcwalton on Thursday January 09, 2014 @04:44PM (#7033480)
Inheritance may not make 1.0.
Re:Rust 0.9 released by Ycros on Thursday January 09, 2014 @05:01PM (#7033600)
I'm finding that my OO code style these days is very composition heavy with pretty much no inheritance use. I think given Rust's type system, I'm not going to miss inheritance much.
Re:Rust 0.9 released by eridius on Thursday January 09, 2014 @05:04PM (#7033616)
I believe Rust wants inheritance primarily for Servo, because the DOM is defined in terms of inheritance.
Re:Rust 0.9 released by pcwalton on Thursday January 09, 2014 @05:13PM (#7033654)
Right. Idiomatic Rust prefers composition over inheritance.
Re:Rust 0.9 released by zanny on Thursday January 09, 2014 @10:22PM (#7034916)
Every language in the universe prefers composition over inheritance =P
Re:Rust 0.9 released by seanmcdirmid on Thursday January 09, 2014 @10:47PM (#7034988)
Not 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.

Re:Rust 0.9 released by moomin on Friday January 10, 2014 @03:40AM (#7035725)
I find that when refactoring code, I often redefine is-a to has-a anyway.
Re:Rust 0.9 released by LBarret on Saturday January 11, 2014 @06:35PM (#7044304)
is-a vehicle --> has 4 wheels
Re:Rust 0.9 released by scardine on Saturday January 11, 2014 @09:41PM (#7044914)
Runtime error: Motorcycle lacks 4 wheels
Re:Rust 0.9 released by banachtarski on Thursday January 09, 2014 @10:52PM (#7035008)
The ones that don't blossom into interface factories which make factory adapters of abstract factories. (I'm looking at you, Java)
Re:Rust 0.9 released by V-2 on Friday January 10, 2014 @04:59AM (#7035919)
For 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...

Re:Rust 0.9 released by jeltz on Thursday January 09, 2014 @08:03PM (#7034378)
If 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.
Re:Rust 0.9 released by pcwalton on Thursday January 09, 2014 @08:16PM (#7034431)
Can'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".

Re:Rust 0.9 released by carterschonwald on Thursday January 09, 2014 @09:43PM (#7034793)
ooh, is this like record subtyping? Have you seen ermine https://github.com/ermine-language or Ur/web? http://www.impredicative.com/ur/

[edit, on #rust it was explained to me that its only for pointers to structs, but thats fine by me]

Re:Rust 0.9 released by dbaupp on Thursday January 09, 2014 @10:16PM (#7034892)
If anyone is interested, the proposal for Rust is detailed in http://smallcultfollowing.com/babysteps/blog/2013/10/24/sing...
Re:Rust 0.9 released by thirsteh on Thursday January 09, 2014 @09:10PM (#7034649)
I think this is a good idea. It seems similar to Go's embedding: http://golang.org/doc/effective_go.html#embedding
Re:Rust 0.9 released by pcwalton on Thursday January 09, 2014 @09:15PM (#7034667)
The difference is that the base struct can call methods on the derived struct, whereas this is not possible with that kind of struct embedding. This is important for some use cases (e.g. the DOM or the render tree).
Re:Rust 0.9 released by thirsteh on Thursday January 09, 2014 @09:26PM (#7034718)
I see.
Re:Rust 0.9 released by jeltz on Thursday January 09, 2014 @11:12PM (#7035060)
Thanks for the answer, and I think I like your solution to the problem.
Re:Rust 0.9 released by dbaupp on Thursday January 09, 2014 @08:10PM (#7034414)
I 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.
Re:Rust 0.9 released by joelthelion on Friday January 10, 2014 @03:33AM (#7035710)
Just because people have overused inheritance in the past doesn't mean it's completely useless.
Re:Rust 0.9 released by masklinn on Friday January 10, 2014 @03:52AM (#7035759)
Nobody has said it was useless.

Although with the right language support, it is useless, composition can stand for it (demo: Self)

Re:Rust 0.9 released by joelthelion on Saturday January 11, 2014 @04:43AM (#7042162)
By that reasoning most programming features are useless (demo: C)
Re:Rust 0.9 released by masklinn on Saturday January 11, 2014 @10:34AM (#7042792)
I'm reasonably certain you completely misunderstood my comment, because C definitely isn't an illustration of it.
Re:Rust 0.9 released by Daishiman on Thursday January 09, 2014 @05:04PM (#7033612)
It's a question of performance more than composition.
Re:Rust 0.9 released by ehsanu1 on Thursday January 09, 2014 @07:51PM (#7034326)
Please elaborate?
Re:Rust 0.9 released by kibwen on Thursday January 09, 2014 @04:50PM (#7033529)
Ah, news to me. I guess it can be introduced without breaking backwards-compatibility.