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

Marcin 'Qrczak' Kowalczyk qrczak at knm.org.pl
Sat Jul 28 19:04:43 EDT 2001


Sat, 28 Jul 2001 22:10:23 GMT, Guido van Rossum <guido at python.org> pisze:

>> I would not make 5/2-3/2 usable as a sequence index. My style is more
>> "typeful". But you decide.
> 
> I am not at all sure!  This should definitely be added as an open
> issue to the rationals PEP.

Well, I was on a walk today and thought that maybe you are right
about that unification :-)

The sure thing is that inexact numbers won't be allowed where a
precise value is needed to determine validity - too bad if "error
in the program"-kind of exception depends on rounding errors.

Arguments for unifying ints with rationals:

- Since 2 == 2/1 and maybe str(2/1) == '2', it reduces surprises
  where objects seem equal but behave differently.

- / can be freely used for integer division when I *know* that there
  is no remainder (if I am wrong and there is a remainder, there will
  probably be some exception later).

Arguments against:

- When I use the result of / as a sequence index, it's usually an
  error which should not be hidden by making the program working for
  some data, since it will break for other data.

- (this assumes that after unification int and rational would be
  different types:)
  Types should rarely depend on values. It's easier to reason when
  the type of a variable is known: I know how I can use it. I can
  determine that something is an int and expect that other objects
  used in this place will be ints too.

- (this assumes the same type for them:)
  Int is a good type in itself, not to be mixed with rationals.
  The fact that something is an integer should be expressible as
  a statement about its type. Many operations require ints and
  don't accept rationals. It's natural to think about them as about
  different types.

-- 
 __("<  Marcin Kowalczyk * qrczak at knm.org.pl http://qrczak.ids.net.pl/
 \__/
  ^^                      SYGNATURA ZASTĘPCZA
QRCZAK



More information about the Python-list mailing list