Hi --

On Sat, 15 Jan 2005, Robert Klemme wrote:

>
> "Mark Hubbart" <discordantus / gmail.com> schrieb im Newsbeitrag 
> news:de63abca05011415224d4c29a1 / mail.gmail.com...
>> 
>> My only argument against the shortcut syntax is that I can't see how
>> often it could be used, except to simulate static typing. I suspect
>> that adding a feature like this would encourage the use of static
>> typing in methods.
>
> Ok, then we need a poll.  Or we should dig into Ruby's std lib to see how 
> often these methods are called.

Not very :-)  For 1.8.2:

$ grep '\.to_str' `find . -name "*.rb"` | grep -v to_string | wc -l
       6
$ grep '\.to_int' `find . -name "*.rb"` | wc -l
       1

(It's around 700 for to_s and 300 for to_i.)

>> In fact, if they need the
>> functionality, then the have to resort to some hack like this:
>> 
>> obj = ObjectThatImplementsTimes.new
>> wrapper = Object.new
>> class << wrapper;self;end.__send__(:define_method, :to_int){obj}
>> 
>> A very ugly hack, just to re-allow duck typing.
>
> The invocation of to_int is already and application of duck typing.

OK, I think I've clarified my big problem with all of this:

How would you move this call to #join to a method signature?

    def meth(a)
      puts a.join(", ")
    end

I think there are only two ways:

   1. put the whole thing, including the ", ", into the signature
      (which I doubt anyone would advocate);
   2. back away from duck typing and rely on something else, probably
      #respond_to?  You're then dealing with the capabilities of the
      object at one level of remove -- which, of course, is something
      one often does, but it's only a subset of available techniques
      for dealing with type and object capability.  (My position is
      that duck-typing - #respond_to? > 0)

In other words, I question whether it's possible to re-model runtime
message-sending as a method signature, without some kind of major
reconception of the whole thing and/or up-front decision to drop
one or more programming techniques.


David

-- 
David A. Black
dblack / wobblini.net