Comment on PEP-0238

Paul Prescod paulp at ActiveState.com
Wed Jul 4 15:54:30 EDT 2001


"Robert J. Harrison" wrote:
> 
>...
> 
> Python does not undermine the distinction between integers and floats.

>>> 5 + 10
15
>>> 5 + "10"
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
TypeError: number coercion failed

> Arithmetic expressions that
> involve only integers currently always result in an integer.

>>> import math
>>> math.cos(5)
0.28366218546322625

>  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
> behaviour,
> and it will not be consistent about the type of result returned from a
> pure
> integer expression.

And that is a problem how? Only people with a history in statically
typed languages seem to expect operations to be type-consistent.

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

Maybe it is helpful for experts to undermine the distinction between
floats and integers and then "surprise" they are different in this one
context. It isn't helpful for newbies.

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

Sure, people with a bunch of programming language experience.

http://www.python.org/doc/essays/cp4e.html

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

If you are consistent about this I might support you. Let's ban
expressions like this:

>>> 1/2.0
0.5

Then Python will be consistent about the fact that integers and floats
are as different as strings and integers.

-- 
Take a recipe. Leave a recipe.  
Python Cookbook!  http://www.ActiveState.com/pythoncookbook




More information about the Python-list mailing list