On 7/23/15 6:56 AM, "Marc =?UTF-8?B?U2Now7x0eiI=?= <schue...@gmx.net>" wrote:
Traits
------
I think the ability to express an interface without buying into
inheritance is the right move. The alternative in D is specifying the
behavior as a template and verifying the contract in a unittest for
the type.

Not only that, but Rust does so much more with traits, e.g. closures.
They seem to be a simple, yet powerful concept, that a big part of the
language is built on.

http://blog.rust-lang.org/2015/05/11/traits.html

On the other hand, it is extremely restrictive in contrast to `static
if()` and template constraints. D's approach is a lot more expressive
and - at least for me - intuitive.

Thanks for the link, good quick read to get the overview of Rust's traits feature. It's ingenious because it integrates static and dynamic dispatch.

For dynamic dispatch, traits are better than interfaces - more flexible, better informed. For static dispatch, they don't hold a candle to D's constraints. This is important because dynamic dispatch is more of a cut-and-dried matter, whereas static dispatch is where it's at.

For static dispatch I think D's template constraints are quite a lot better; they have a lot more power and offer a lot more to promise. They are an out-of-the-box solution that's a bit unwieldy because it's new enough to not yet have established idioms. In contrast, traits come from straight within the box.

From a language perspective, it is my belief that Design by Introspection (enabled collectively by template constraints, introspection, compile-time function evaluation, and static if) is the one crushing advantage that D has over any competitor. Things like range-based algorithms are good but easy to copy and adapt.

The faster we manage to get creative with Design by Introspection and describe it, systematize it, create compelling designs with it, the quicker will D win the minds and hearts of people.

There's a lot at stake here. An question often asked by would-be users is "What does D offer that's special?" or "What does D offer over language Xyz?" As we all know there are many answers to that. Maybe too many. Now I know what the answer is: Design by Introspection.


Andrei

Reply via email to