Does python support multi prototype.
Jorgen Grahn
jgrahn-nntq at algonet.se
Sun Aug 8 13:27:53 EDT 2004
On Wed, 04 Aug 2004 23:08:28 -0400, Peter Hansen <peter at engcorp.com> wrote:
> Jorgen Grahn wrote:
>
>> Your code was kind of elegant, but kind of misses the point with
>> overloading, I think. At least, it's not anything I'd want to do in most
>> situations where overloading would have been nifty in C++. IMHO.
>
> Okay, fair enough. Would you be able to describe any situation
> in which you have found overloading to be useful in C++. (Note,
> not merely nifty, but useful?)
Well, it's needed for output streams to work -- the << operators which push
objects onto streams cannot be member functions - and they better have the
same "names".
I also suspect it's vital to generic programming using templates and such ...
Also when you want common functions that operate on objects without being
members -- the thing Python solves by translating len(x) to x.__len__() etc.
> In my experience, most of the
> cases where I used it in C++ were actually cases of poor design
> and should have been done differently, in hindsight.
If we are talking member functions, you may have something there ...
On the other hand, I don't see embedding a type name in the method name as a
better alternative, ever.
I wrote a small Python helper class yesterday, for reasons too complicated
to explain here. I called it "Cluster", and it was really just a set of
(x,y) points which I expected to be roughly clustered around some point.
I needed to find the distance between (the center of) a Cluster and a point,
but also between two Clusters.
Had that been C++, I would have been tempted to add two methods:
double Cluster::distance(const Cluster&) const;
double Cluster::distance(const Point&) const;
but for some reason (asymmetry?) that feels like the easy and slightly wrong
way out.
Anyway, this was Python so I didn't have to think much about that ;-)
/Jorgen
--
// Jorgen Grahn <jgrahn@ ''If All Men Were Brothers,
\X/ algonet.se> Would You Let One Marry Your Sister?''
More information about the Python-list
mailing list