proposed language change to int/int==float (was: PEP0238 lament)

Gareth McCaughan Gareth.McCaughan at pobox.com
Tue Jul 24 20:05:34 EDT 2001


Stephen Horne wrote:

[I said:]
>> The different behaviour of "/" on floats and ints isn't
>> polymorphism, it's overloading. Two different operations.
>> Closely related, of course, but different. Generally
>> "polymorphism" is reserved for when what's being done
>> is "the same thing" in both cases.
> 
> It *is* the same thing in both cases - float division is nothing more
> than a logical extension of integer division. Even mathematicians know
> that ;-)

I am a mathematician, and I do not know, or even believe,
that "float division is nothing more than a logical extension
of integer division" if "integer division" means what
Python presently does.

To any mathematician on the planet, 1/2 is, well, 1/2.
A rational number quite different from 0.

This isn't necessarily an argument for making division
return rationals when handed integers -- well, it is, but
it's not necessarily a very *strong* argument for that.
(It would involve a non-trivial amount of work, the
results would be amazingly frustrating in practice
unless the numerator and denominator had the sematics
of longs rather than ints, and simple programs could
become mysteriously inefficient. Some people would find
that worse than them just doing the wrong thing.)

If I were re-designing Python from scratch and didn't
care about backwards compatibility, then I'd give it
unified ints and longs, and rationals, and I'd make
division of integers produce rationals. But I'm not,
and since Guido is a better language designer than me
it's probably just as well.

-- 
Gareth McCaughan  Gareth.McCaughan at pobox.com
.sig under construc



More information about the Python-list mailing list