On 2010-10-16 09:54:50 -0400, Andrei Alexandrescu <seewebsiteforem...@erdani.org> said:

Walter recognized it instantly, as I think most should. Isn't "duck typing" really spread out there?

"duck" is a misnomer.

First, it's dubious whether this "duck" function implements what most people understand by "duck typing".

Wikipedia says "In duck typing, one is concerned with just those aspects of an object that are used, rather than with the type of the object itself. [...] If the object does not have the methods that are called then the function signals a run-time error." Your "duck" function isn't concerned about the aspects of an object that are used, it's concerned by the aspects of an objects that can implement a certain interface type. Duck typing is much more synonymous to dynamic dispatch, where errors are reported at runtime, than to the adaptor pattern. The two concepts are not totally unrelated, but they're not the same thing either.

Second, you meant "duck" as a noun, but "duck!" looks like a verb to me for two reasons: because of the exclamation mark and because it's a function. I fear that in the absence of prior knowledge of that function it gets understood as:

        duck (verb)
        - lower the head or the body quickly to avoid a blow

making sense only if you're writing some sort of game. Since we're looking for a verb, why not "quack!". :-)

"as!" doesn't have the verb ambiguity problem nor the terminology problem, and it's basically a continuation of the "to!" scheme. Personally, I'd go for "as!". But I'd prefer even "adaptTo!" or "adapt!" rather than "duck!".

--
Michel Fortin
michel.for...@michelf.com
http://michelf.com/

Reply via email to