Comment on PEP-0238

Paul Prescod paulp at ActiveState.com
Tue Jul 3 12:21:26 EDT 2001


"Robert J. Harrison" wrote:
> 
> Paul Prescod <paulp at ActiveState.com> wrote in message news:<mailman.994084684.19932.python-list at python.org>...
> > ... Most people do not expect these four
> > expressions to yield different results:
> >
> > 1.0/3.0
> > 1/3
> > 1.0/3
> > 1/3.0
> 
> I completely disagree, and as someone who has taught math, science and
> programming, it is quite clear to me that 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.

> > ... 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.

> .... The existence of the standard
> __coerce__ method illustrates the importance of such expressions.

I agree!

>...
> I might accept an argument that says that anything that coerces
> (automatically!) to an integer with no loss of precision can be
> used to index a list.  But how to distinguish between 1, 1+eps
> (eps=machine precision), and 1.1?  How many elements are there
> between elements [1] and [2]?

That's a different discussion altogether but I would say that anything
that evaluates equal to an integer could be valid as an array index. But
I don't care enough about that to argue it one way or the other.

>...
> 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.
-- 
Take a recipe. Leave a recipe.  
Python Cookbook!  http://www.ActiveState.com/pythoncookbook




More information about the Python-list mailing list