Comment on PEP-0238

Robert J. Harrison rjh at
Wed Jul 4 07:41:10 CEST 2001

Paul Prescod wrote:
> "Robert J. Harrison" wrote:
> > ... the distinction between integer and real arithmetic is an 
> > essential concept.
> If it is such an essential concept, why does Python undermine the
> distinction by coercing between types. And by the way, why doesn't the
> division of an integer by a float result always in an integer? Because
> Python treats integers as a special case of floats? Except in *one
> particular context*. Hmmmm.

Python does not undermine the distinction between integers and floats.  
Arithmetic expressions that
involve only integers currently always result in an integer.  It is the
new proposal that coerces integers to floats, but only if a
div operation is performed, otherwise you get an integer.  So the new
proposal will perform more automatic coercions than the current
and it will not be consistent about the type of result returned from a
integer expression.

> > > ... Why is automatic coercion *ever* necessary?
> >
> > Mixed type expressions are almost inevitable.  It would take a much
> > larger reworking of the Python numerical model than proposed by
> > PEP-0238 to do away with that.
> Exactly. PEP-0238 strives to do away with a single operation that is out
> of sync with Python's general treatment of integers as a special case of
> float. The only othre way that behaviour could be made consistent would
> be to remove all of the other cases where it uses this type hierarchy.

Python's current treatment of integers is NOT as a special case
of float.  It is to treat them as a distinct integer type.  It is only
in MIXED type expressions that Python helpfully converts them.
> > My point was rather poorly made.  The new
> > proposal has simply moved the point at which people need to understand
> > the distinction between real and integer arithmetic.  Currently it must
> > be understood when the operation is performed.  In the new proposal it
> > must be understood when the result of the operation is used.
> Nobody argues against understanding. But understanding is eased if you
> do what people expect. People believe that the integers are a special
> case of floats. Python encourages them in that belief in most places
> other than this one.

Who expects?  You are already seeing in this discussion that many
people think that the current behaviour is not only what they expect
but is actually very justifiable. 

Again, my major objection to this proposal is that it gives us
nothing and breaks a lot of existing code.  The proposal is based upon 
the supposition that uniting floats with integers makes programming
easier to learn for beginners, but this is absolutely not consistent
with my experience in teaching programming using Python and other
languages (including Maple that has rationals).
All programmers must very soon appreciate the different nature of
integer and floating point (or rational) arithmetic in order to
address discretized quantities such as lists, files, strings, etc. 

> --
> Take a recipe. Leave a recipe.
> Python Cookbook!

Robert J. Harrison (rjh at

More information about the Python-list mailing list