Overloading methods in C API
Grant Edwards
grante at visi.com
Sat Jan 18 14:56:24 EST 2003
In article <Xns9307CD595EDCBrcamesz at amesz.demon.nl>, Robert Amesz wrote:
> Grant Edwards wrote:
>
>>> Is method/function overloading common in Python modules?
>>
>> No. It's isn't supported. The language does not allow it.
>> Therefore, it is not common.
>
> It's not that the language doesn't allow it, it's just that dynamic
> typing makes it impossible to decide beforehand what methods/functions
> would be called.
The language doesn't allow one to declare the types of function/method
parameters. Therefore function/method overloading is not possible. In my
mind, that can be summarized as "the language doesn't allow it."
>>> Is it looked down upon?
>>
>> It is not allowed by the language design. I suppose that's a
>> pretty good indication that it's "looked down upon."
>
> No, it's not "looked down upon". Take, for example, the % operator for
> strings: it allows things like:
That's operator overloading, which I think of as different than
function/method overloading.
>
> "Single value: %d" % 43
>
> or:
>
> "Multiple values: %s %d" % ("one", 2)
>
> or even:
>
> "Using a dict: %(first)s %(second)d" % {"first": "one", "second": 2}
>
> That's a pretty overloaded function, if you ask me, and it's part of
> core Python. It's just that in Python you have to do this manually. Ah,
> well, "explicit is better than implicit", to coin a phrase.
For whatever historical reasons, operator overloading and function/method
overloading are usually considered as two separate language features. C and
python have the former but not the latter. C++ has both.
--
Grant Edwards grante Yow! A shapely CATHOLIC
at SCHOOLGIRL is FIDGETING
visi.com inside my costume...
More information about the Python-list
mailing list