On Sat, 11 Jun 2005, Eric Mahurin wrote: > --- "Ara.T.Howard" <Ara.T.Howard / noaa.gov> wrote: > >> TWENTY_SIX_KEWORDS_AT_ONCE = ('a' .. 'z').to_a >> >> def method argv >> pa = parsearges(argv){ >> required_argument 'foobar' >> keywords TWENTY_SIX_KEWORDS_AT_ONCE >> } >> end > > I could see this being useful. But, I don't care for > additional "type" checking over what the code already does. well, me too for the most part and i rarely use the the :type/:ducktype options myself - but i do use them at times... > So you just want the check to occur earlier than when the code > makes the check. That sounds like a reasonable usage when the > method can take a very long time (> a few minutes). exactly. i end up with stuff like that alot around here... > Maybe you could think of duck-typing as when functionally a method doesn't > need to categorize the "type" of any of its arguments or overconstrain what > its argument capabilities should be. Implementation-wise, you may use > respond_to?, class, etc but it should have equivalent functionality to some > implementation that didn't use these. I think this early checking you do > would just be an implementation thing. Another case I can think of is when > you might have a more efficient (i.e. C) implementation for a specific > class. this seems more or less correct... i haven't considered it quite that way. > class. For example, if you wanted to make a duck-typed Regexp class, you > might special case the String class: > > def Regexp > def match(sequence) > if String===sequence > super # fast C implementation > else > # a less efficient pure duck-typed implementation > end > end > end > > I think it would be great if more of the built-in classes were duck-typed > like this. at first glance this sounds o.k. - but i think i would lead to many sublte errors like we see in perl. that may sound like i'm contra-dicting myself; after all, i use duck typing all the time. but there is a big difference between user written code and language level libs : namely that i know with great certainty the environment much of my code runs in. for instance i might know that only i will ever use it ;-) that's not the case with built-ins though and i, for one, am glad '0' will never act like 0. i conceed that there are some cases where it would might make sense though - it should just be considered very very carefully for core code. cheers. -a -- =============================================================================== | email :: ara [dot] t [dot] howard [at] noaa [dot] gov | phone :: 303.497.6469 | My religion is very simple. My religion is kindness. | --Tenzin Gyatso ===============================================================================