From: Mark Wilden Date: 2008-05-29T07:23:30+09:00 Subject: Re: The duck's backside On May 28, 2008, at 1:44 PM, David Masover wrote: >> The only point of using Ruby (or any other tool in the universe) is >> to >> get a job done. :) I would never use a Ruby feature just because Ruby >> makes it possible. > > Put it this way: What's the point of using, say, Erlang, if you > never use its > concurrency features? All I can do is repeat what I said: the ONLY point to ANYthing (in programming) is as a means to accomplish some purpose. If using Erlang accomplishes a given purpose best, then it should be used, no matter what its concurrency capabilities. One reason might simply be that a given programmer is more comfortable in that language than another, and can therefore accomplish the task faster. > Granted, Ruby has a bit more going for it, but a lot of the joy of > using Ruby > is how much less work you end up having to do when you don't have to > think > about types too much. I think you mean "classes," not "types." At any rate, I don't see how Numeric === v involves more work than the alternative, so I don't think that criterion applies here. > No, it says "v is of class Numeric." It's very explicit, and makes the > assumption that anything which acts like a number will eventually > inherit > from Numeric. Well, the desired goal is in fact to recognize objects that are numeric. One of the purposes of classes in OOP is to categorize things. >> I don't even know what the ability to respond to :to_int means. > > I think it would be :to_i, actually... And I'd probably just call > foo.to_i, > rather than testing for the existence of to_i. :to_i is actually rather different, as it will convert a string (even a non-numeric string like "2a"). That's an example of having to know the implementation of the method to determine whether testing responds_to? makes sense. For all I know, :to_i may in fact be the desired method, but Elizabeth used :to_int, and I assume it was for a reason. > Remember the above -- I could actually completely redefine Array, or > Numeric, > etc. So even your assumption that "Numeric === foo" tests for > Numeric is > really only based on convention -- you're assuming that no one, > anywhere in > your code, is doing stuff like this: > > Numeric = nil That's not merely being unconventional--that's insanity. :) Anyway, it applies even more so to methods, which aren't in the global namespace. >> (think Cowboy#draw and Artist#draw). > > Yes, that is a downside of duck typing, as currently implemented, > but doesn't > really apply to :to_i. > > Also, context matters. If Cowboy and Artist are both in a GUI widget > library, > that Cowboy is asking for trouble. That's true, but it wasn't my point. The question is whether all methods with the same name in all active classes should be semantically equivalent. I think that's a rather larger assumption than that Numeric means "numeric." ///ark