[PEAK] generic function signature changes
Phillip J. Eby
pje at telecommunity.com
Thu Jun 15 14:47:32 EDT 2006
At 07:26 AM 6/15/2006 -0400, Kevin Dangoor wrote:
>Am I correct that it is harder to change a generic function's
>signature than it is to change an ordinary function's signature?
Actually, it's the *same* effort. See below.
> Let's
>say you have this function:
>
>def foo(bar)
>
>As an ordinary Python function, you can do this:
>
>def foo(bar, baz=None)
>
>without breaking any subclasses (if this were a method)
That's actually not true - you'll break subclasses that override the
method, and this situation is precisely the same. That is, the methods of
a generic function are just like methods in subclasses. In fact, if you
are using only single-dispatch on the first argument, it is *exactly* the
same: you have one GF method for each subclass.
>or anyone else
>using the function.
And those don't break in the generic function case, either.
>But, if you add an additional, even optional,
>parameter to a generic function, all of the implementers of that
>function need to change as well...
>
>Is that right?
Yes - just like if you add a parameter to a method in a base class or
interface -- all the implementers or overriders of the method need to
change as well.
More information about the PEAK
mailing list