Rant after trying Rust a bit

Walter Bright via Digitalmars-d digitalmars-d at puremagic.com
Sat Jul 25 02:53:28 PDT 2015


On 7/24/2015 7:28 PM, Jonathan M Davis wrote:
> I confess that I've always thought that QueryInterface was a _horrible_ idea,
> and that if you need to cast your type to something else like that, you're doing
> something wrong. *shudder* I really have nothing good to say about COM actually...

I am not explaining this properly. Trying again,

     void foo(T: hasPrefix)(T t) {
        t.prefix();    // ok
        bar(t);        // error, hasColor was not specified for T
     }

     void bar(T: hasColor)(T t) {
        t.color();
     }

The Java, COM interface systems do not write code like:

     void foo(T: hasPrefix, hasSuffix)(T t) {
        t.prefix(); // ok
        bar(t);
     }


They write it something like:

     void foo(hasPrefix t) {
        t.prefix();
        s = cast(hasSuffix)t;
        if (s) bar(s);
        else RuntimeError(message);
     }

So no, statically checked traits and concepts are not used in the OOP world.


More information about the Digitalmars-d mailing list