From: dblack@... Date: 2003-09-13T10:29:52+09:00 Subject: Re: Duck Typing Hi -- On Sat, 13 Sep 2003, Jim Weirich wrote: > In the Method Redefinition thread, this explanation of Duck Typing is > offered ... > > > What Duck typing is based mostly on realising what sort of operations > > you want to do with the object and testing for those operations, > > rather than testing for the class. As Dave is fond of saying: type and > > class aren't the same. > > This is slightly different than my understanding of Duck Typing. I > would phrase it more like this: > > Duck typing is based mostly on realising what sort of operations > you want to do with the object and just doing them, rather than > worrying if the object inherits from the proper base class or > interface. > > I've heard others also explain duck typing in terms of explicitly > testing for particular methods and I feel that leaves the wrong > impression. If we say Ruby supports duck typing, then newcomers are > left with the impression that you need to do a lot of testing for > particular methods (which you don't). Or even, more generally, left with the impression that there's an on/off switch: if you say "is_a?" a lot, then you're not doing duck typing, whereas if you say "respond_to?" a lot, then you are -- when in fact it's really Ruby that's doing the duck typing, and you're just deciding how to react to it. I think I remember the phrase "duck-typed language" from one of your posts a while ago, which I thought really summed it up (though it may be a harder phrase to break people in with :-) It captures the idea that the inferential, dynamic concept of type resides in the language itself. David -- David Alan Black home: dblack@superlink.net work: blackdav@shu.edu Web: http://pirate.shu.edu/~blackdav