On Sat, 16 Oct 2010 00:37:10 +0400, Andrei Alexandrescu <seewebsiteforem...@erdani.org> wrote:

I was talking to Walter about Kenji's adaptTo. We both think it's a very powerful enabler, but adaptTo is a bland name. After discussing a few marketing strategies, I proposed "duck". It's short, simple, and evokes "duck typing".

class C
{
     int draw(){ return 10; }
}
interface Drawable
{
     long draw();
}
...
auto c = new C;
auto d = duck!Drawable(c); // awes

Kenji, I'll be looking forward to your submission :o). Would be great to allow structs to duck, too!


Andrei

There is a lot in common between to and adaptTo (even the original names are similar). 'to' converts one type to another (unless the two are implicitly castable) and 'adaptTo' does the same. 'adaptTo' can transform some types that 'to' can't, and vice versa.

In my opinion, they don't compete but supplement each other. As such I would prefer merging the two together:

auto c = to!(Drawable)(c); // try casting to Drawable first, return adaptTo(Drawable) if it fails.

The difference between 'as' and 'to' is subtle yet both names are short and might be confusing for many people, not only novices. Yet 'as' is better than 'duck' imo.

Reply via email to