Rant after trying Rust a bit

jmh530 via Digitalmars-d digitalmars-d at puremagic.com
Thu Jul 23 09:54:50 PDT 2015


On Thursday, 23 July 2015 at 15:38:53 UTC, Adam D. Ruppe wrote:
>
> It isn't really expanded upon, but the : Interfaces at the top 
> here tells you can inherit them:
>
> http://dlang.org/interface.html
>
> It doesn't show an example in the text of an interface 
> extending another interface, but it does say "interfaces can be 
> inherited".
>

I see that now. It's there, but it's practically a throw-a-way 
line. I've looked at that page a bunch of times and skipped over 
it each time. This is a broader problem with D's reference pages.

Compare
http://dlang.org/interface.html
with
https://doc.rust-lang.org/book/traits.html
which is better?

Rust's documentation uses clear examples to show how something 
should be used and the most important features. By contrast, 
there are many parts of D's documentation that someone with 
less-than-expert programming knowledge will find quite difficult 
to understand.

For instance, look at
http://dlang.org/function.html
you have to scroll down for quite a while before you even get to 
anything useful. Then, what's the first thing that comes up? 
Something about contracts, return values, bodies, purity. Not 
"this is what a D function is".

I'm all for a complete reference of every D feature, but there 
needs to be some step up in terms of difficulty of the material. 
Start with the basics, then work up into all the specifics. I'd 
say at a minimum some of this documentation needs to be broken up 
into several pages.

There seem to be a lot of places where I could improve the D 
documentation. However, I feel like if I start going crazy with 
changes I might get some push-back...

>
> BTW you can also check interface conversion for objects in a 
> template function and get static dispatch that way... sort of:
>
> void something(T : Foo)(T bar) {
>         bar.foo();
> }
> void main() {
>         Foo bar = new Bar();  // explicitly using the interface
>         something(bar); // leads to this calling "foo"
>
>         // but if you did "auto bar = new Bar();" or "Bar bar"
>        // it would call "foo from bar"
> }

This is cool and I wasn't aware that you could do this. I was 
trying to use std.traits' InterfacesTuple to test that a class 
had a particular interface.

However, I also find it a bit confusing. I don't understand 
precisely what it means when the interface is on the left. It's 
like you're using the class to create an object of a type the 
same as the interface...Nevertheless, the interface page says you 
can't do this
D d = new D();
where D is an interface. However, it also says that you can
D d = cast(D) b;
where b is some an object of some other class B that inherits the 
interface D. You example does not fit either of these cases. 
Then, if you change Foo to not be final and Bar to not override 
and run it, it will call "foo from bar" regardless of whether you 
do
Foo bar = new Bar();
or
Bar bar = new Bar();


More information about the Digitalmars-d mailing list