On Mon, Jan 31, 2011 at 9:00 AM, Gary Wright <gwtmp01 / mac.com> wrote:
>
> On Jan 31, 2011, at 5:16 AM, Shadowfirebird wrote:
>> Or, indeed, the practical case - at the very heart of Ruby is the idea o=
f duck typing. =A0Duck typing rules out method overloading, because paramet=
ers would have to have set types before you could have a signature. =A0Pres=
umably no-one is suggesting that we should have fixed typing in Ruby?
>>
>
> I think the original poster provided an example of overloading based on t=
he number of parameters but not their type.
> Even restricting yourself to overloading by arity is a bit problematic in=
 Ruby because the arity still has to be determined (in some cases) dynamica=
lly:
>
> args =3D [1,2]
> foo(*args) =A0 =A0 =A0# two arguments
> args << 3
> foo(*args) =A0 =A0 =A0# three arguments

Actually, arity of callsite is always calculated  in Ruby to know if
you should throw an ArgumentError (3 for 0 specified sort of errors)
against the method you are calling.  It seems like overloading based
on arity is not such a bad idea to me based on some of the common
arity parsing idioms people do by hand in the first few lines of their
methods.  What implementing arity-based overloads would do is get rid
of most of this code we put at the top of methods and perform that
logic in the Ruby implementation itself (in MRI in C vs in Ruby).

Stylistically, I think the biggest issue is not realizing there are n
overloads and then implementing less than n overloads in an overridden
class.

-Tom

--=20
blog: http://blog.enebo.com=A0 =A0 =A0=A0 twitter: tom_enebo
mail: tom.enebo / gmail.com