Comment on PEP-0238

Guido van Rossum guido at python.org
Sat Jul 7 09:33:55 EDT 2001


"Terry Reedy" <tjreedy at home.com> writes:

> GvR:
> > I currently favor div(x, y) over x//y and x div y.  Maybe also add
> > mod(x, y) for symmetry (that would also explain divmod() as a
> > messenger from the future :-).
> 
> Since I do not like the change, as explained previously, I would prefer the
> least change, which would be // with div second.  // would not be new
> keyword and breaks nothing sensible that I can think of.  An operator form
> would run as fast as now since it would be compiled inline as now.  A
> function call would be slower and make integer division look much more
> wierdly asymmetric than it actually is.  I suspect that some newbies and
> CP4E people would find *that* (div()) strange.
> 
> Terry J. Reedy

Indeed, the beauty of binary operators is that they help the human
programmer quickly understand an expression.  Since we're used to the
commutative and distributive laws and various other laws that apply
(when they apply!!!), it takes less cognitive effort to understand
"x+y+z" and move on to the next expression than "add(add(x,y),y)".
Occasionally, the visual arrangement of operators and operands will
remind us of a rearrangement that does the same thing more
efficiently.  (ABC's head designer, Lambert Meertens, developed a
whole theory of programming based on this idea; search the web for
"algorithmics".)

But there are dimisishing returns.  Integer division isn't that
common, and there are few distributive or commutative laws that apply
to it (those are mostly reserved for addition and multiplication).

The proposal of "//" got a lot of opposition from folks who are
concerned that it would confuse people with a C++ or Java background
too much, because it's a comment there.

The "div" keyword would be ideal except for the added complexity of
adding a new keyword to the language -- do we need a separate warning
phase here, too?

(Hm.  For various reasons I'm very tempted to introduce 'yield' as a
new keyword without warnings or future statements in Python 2.2, so
maybe I should bite the bullet and add 'div' as well...)

--Guido van Rossum (home page: http://www.python.org/~guido/)



More information about the Python-list mailing list