On 8/6/06, Yochen G. [email protected] wrote:
puts aString.reverse
Does Duck-Typing mean “ah, the programmer always knows, which kind of
objects this method expects. Thus never an error will occur.”? This
seems very optimistic to me if not naiv. You cant just trust that the
any programmer who uses your class knows what exactly is happening in
your method and which type of object is required.
Thankful for any hint.
Well what a nice occasion. I have to reply fast because I will be
outnumbered fast 
I have for quite a while now spoken up for some mechanisms for
defensive
programming and early failure, without success so far.
What you can do e.g. is
def aMethod something
raise WhateverException, “whatever info useful” unless String ===
something
you might also distinguish sometimes between nil and other problems
However I have to conceede a point to the ducktypers (which is quite a
nice
feature I never want to see disappear) sometimes
you want something to reply to #reverse and to #+, ( a String object
might
not reply to these messages ).
So you could just fail or fail with a more meaningful message like this
raise GreatExplanation, “sage sayings” unless
something.respond_to?:reverse
I still think it would be great to have an expressive syntax about this
like
e.g;
def act actor : Actor
def act actor is Actor
def act actor where Actor === actor
def act actor : SomeThing
note that SomeThing could also be a module and ruby should check if the
instance methods of SomeThing are replied to by actor.
Thus just doing kind of an automated duck type check.
Hope you do not mind using your thread for some lobbying 
Cheers
Robert
Regards,
Yochen
–
Posted via http://www.ruby-forum.com/.
–
Deux choses sont infinies : l’univers et la bêtise humaine ; en ce qui
concerne l’univers, je n’en ai pas acquis la certitude absolue.