From: Massimiliano Mirra Date: 2002-09-29T21:33:07+09:00 Subject: Re: thoughts on typelessness On Sun, Sep 29, 2002 at 12:09:32PM +0900, dblack@candle.superlink.net wrote: > Another thing people often point to that might deter people from > learning a truly type-unchecked programming style is the wordiness of > the most often-mentioned alternative, the "respond_to?" test: > > thing.action if thing.respond_to?(action) Do you really want your method to go on even if `thing' doesn't respond to `action'? Similarly, would you do the following? thing.action if thing.is_a?(Thing) That would look as redundant (and dangerous). > This has the look and feel of duplicate, workaround code. Whereas > this: > > raise ArgumentError unless obj.is_a?(Thing) Sorry David, I feel you're comparing apples and oranges here. :-) I don't think `thing.action if thing.respond_to?(action)' is a likely case. The following would: raise ArgumentError unless thing.respond_to?(action) thing.action Which as you can see is just symmetric to: raise ArgumentError unless obj.is_a?(Thing) thing.action > the #respond_to? test itself is by no means the most concise or > elegant available idiom. If verbs were always chosen for method names, this could be nice: obj.can?(:mkdir) And this wouldn't be too bad: def meth(obj) continue if obj.can?(:mkdir) and obj.can?(:recurse) and obj.can?(:list) Or more concise: def meth(obj) continue if obj.can?(:mkdir, :recurse, :list) Massimiliano (bard on IRC)