Multiple constructors
Caleb Hattingh
caleb1 at telkomsa.net
Sun Feb 6 23:10:21 EST 2005
Hi Philip
> C++ to Python is a steep 'unlearning' curve...
That's worthy of QOTW. I decided not to reply to this thread earlier, but
you just convinced me otherwise :)
I work in Delphi a lot, which is in a lot of respects very similar to C.
I have come to the conclusion that function overloading was introduced to
allow the same calling syntax and even functionality to be applied to
different *types*. This is a consequence of the fact that in Delphi and
C, for example, typing is static.
In a dynamic language like python, however, overloading isn't necessary.
Not only can the *type* of a function argument be determined at run-time,
the *number* of arguments can as well.
Though Alex indicated differently earlier, I intend to always use an "if"
statment inside one constructor to initialise any class in the situation
where the arguments may be different in number and type. I don't have the
years of experience that Alex has, however, so I may end up regretting it
but right now, it seems to me to be the clearest approach in this
situation.
thx
Caleb
More information about the Python-list
mailing list