[Python-ideas] PEP 428 - object-oriented filesystem paths

Andrew McNabb amcnabb at mcnabbs.org
Sat Oct 6 23:45:40 CEST 2012


On Sat, Oct 06, 2012 at 01:54:21PM +1300, Greg Ewing wrote:
> Andrew McNabb wrote:
> 
> >This is the difference between C++ style operators, where the only thing
> >that matters is what the operator symbol looks like, and Python style
> >operators, where an operator symbol is just syntactic sugar.  In Python,
> >the "/" is synonymous with `operator.div` and is defined in terms of the
> >`__div__` special method.  This distinction is why I hate operator
> >overloading in C++ but like it in Python.
> 
> Not sure what you're saying here -- in both languages, operators
> are no more than syntactic sugar for dispatching to an appropriate
> method or function. Python just avoids introducing a special syntax
> for spelling the name of the operator, which is nice, but it's
> not a huge difference.

To clarify my point: in Python, "/" is not just a symbol--it
specifically means "div".

> The same issues of what you *should* use operators for arises in
> both communities, and it seems to be very much a matter of
> personal taste.

Overriding the div operator requires creating a "__div__" special
method, which I think has helped influence personal taste within the
Python community.  I personally would feel dirty creating a "__div__"
method that had absolutely nothing to do with division.

Whether or not the sense of personal taste within the Python community
is directly attributable to this or not, I believe that overloaded
operators in Python tend to be more predictable and consistent than what
I have seen in C++.

--
Andrew McNabb
http://www.mcnabbs.org/andrew/
PGP Fingerprint: 8A17 B57C 6879 1863 DE55  8012 AB4D 6098 8826 6868



More information about the Python-ideas mailing list