duck!

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Sat Oct 16 10:19:36 PDT 2010


On 10/16/2010 11:35 AM, kenji hara wrote:
> I'm not a native English speaker, so you are well about naming than I.
>
> But, by two reasons, I think 'duck' isn't good.
>
> 1.
> 'Duck Typing' is phenomenon, not doing.
> - auto d = adaptTo!Drawable(c)
> - auto d = duck!Drawable(c)
> Which is more explainable that this statement does?
> I think adaptTo is more better.

The problem with "adaptTo" is that, just like itoa or printf, it is too 
boring to have marketing value. I think the feature is going to be 
_big_. We can't leave a big feature to a name like "adaptTo". The New 
York Times won't have a headline like "adaptTo changes the name of the 
game".

This is also part of my beef with "as" or "to" for the feature. "As" is 
difficult to talk about. "Oh my God, D has 'as'!" "Has ass?"

I'd go with the longer "ducktype". Length is not as important as 
evocative power and brand name!

auto d = ducktype!Drawable(obj);

99.99% of programmers will have an idea of what's going on.

> 2.
> I'm now implementing function getting original object from
> interface(like Drawable).
> ----
> auto c = new C();
> auto d = adaptTo!Drawable(c);
> ...
> auto c2 =  = XXX!C(d)
> assert(c2 is c);
> ----
> In this case, XXX's name may be antonym of adaptTo.
> What is the antonym of 'duck'?

No need for an antonym. Just apply again. It is its own inverse and 
makes everything simple for everyone:

----
auto c = new C();
auto d = ducktype!Drawable(c);
...
auto c2 =  = ducktype!C(d)
assert(c2 is c);
----

Boom! You're done.


Andrei


More information about the Digitalmars-d mailing list