Tim Bates wrote:

<snip/>

> 
> At [1], Dave Thomas describes Duck Typing as "a way of thinking about 
> programming in Ruby." I think he means to go a step further than that - 
> Duck Typing is the _best_ way of thinking about programming in Ruby, and 
> possibly the _only_ way; as David Black puts it:
> 
> "I think the concept of duck typing needs to be supplemented and 
> expanded on. if, as seems to be the case, Dave thinks of it as a 
> component of programming style, then it doesn't address language design 
> itself. As long as duck typing is viewed as a stylistic choice, rather 
> than a radical language principle, the door is always open to people 
> saying 'I don't do duck typing', by which they usually mean that they 
> use kind_of? a lot... of course Ruby itself *does* do duck typing, 
> whether a given programmer thinks they're doing it or not."

> 
> Using kind_of? (or responds_to?) a lot isn't "not doing Duck Typing", 
> it's simply adding in at run time the kinds of checks that Statically 
> Typed languages do at compile time, in a usually verbose and necessarily 
> incomplete fashion.
> 
> Rather than trying to make Ruby do Static Typing because one is from a 
> Static Typing background and that's what one is comfortable with, one 
> should become comfortable with the dynamic nature of Ruby instead. 

But why?

That's somewhat rhetorical; I'm happier with duck typing, but there 
seems to be two issues here.  One is understanding what ducking typing 
is.  The other is understanding what it buys you over static typing.

I don't think there's all that much misunderstanding over the former, 
but the latter is a sticking point for some people.

One (possible, and not mine) argument against duck typing is that you 
are essentially required to write assorted unit tests beyond checking 
for operationally correct behavior; the compilation step for a staticly 
typed language offers these (albeit compulsory) "unit tests" for free.

To me, that's the rub.  A compiler forces me to write code to pass tests 
that may have little bearing on the program's actual operation; the 
overhead tends to outweigh the speed of development offered by duck 
typing, even factoring in the "extra" unit tests I may have to write.


James