Overloading methods in C API

Donn Cave donn at drizzle.com
Sun Jan 19 13:30:01 EST 2003


Quoth martin at v.loewis.de (Martin v. =?iso-8859-15?q?L=F6wis?=):
...
| It appears that this is a matter of terminology. My definition is "an
| operator is overloaded if the same operator has different effects
| depending on the number and types of its arguments". It appears that
| this terminology is shared by a number of people in this group.
|
| My guess is that people who had formal training in a single language
| will associate any term with the definition that this term had for
| this language. People who have been exposed to more languages tend to
| accept generalizations as useful, too.

Maybe it would help to consider why we're asking.  If the goal is to
arrive at an explanation that resolves some potential confusions about
how Python might work, I propose that "overloading" is a term we're
better off without.

Isn't it reasonably true that operators in Python are a notational
convenience for the same method dispatch that's conceptually used
anywhere else?  "a + b" is "a.__add__(b)".  It has different effects
depending on number and type of its arguments, but not really - if 
b is 9 or "hi" or [] makes no difference, the same function will be
called notwithstanding.

The complications - a.__add__ may not exist, b.__radd__ may be called
then, pages of code inside Python may be devoted to sorting out the
possibilities - are just footnotes.  Tim Peter's explanation of why
Python doesn't have overloading applies just the same to operators -
lacking type declarations, there's still no way to spell it.

	Donn Cave, donn at drizzle.com




More information about the Python-list mailing list