A use for integer quotients

Steve Horne sh at ttsoftware.co.uk
Mon Jul 23 17:34:01 CEST 2001


On Mon, 23 Jul 2001 11:46:45 GMT, Guido van Rossum <guido at python.org>
wrote:

>This is why making / fractional division and // truncated division
>will reduce the number of bugs in new code: for all occurrences of

If that is what you do, any *intentionally* integer divisions are
going to break. You can't justify that by claiming that one or two
cases are buggy the way they are - the *majority* is *correct* usage
and will *become* bugs *because* of the change.

>Note that this kind of bug is unique to Python (or dynamically typed
>languages in general): in C, the arguments would have been declared as
>floats and the problem would have been prevented.

Then perhaps we need a way of attaching implicit type assertions to
variables and function arguments - NOT to the data of course as there
is no point, but any assignment made to a variable which does *not*
match the type assertion attached to it should either cause an error
or, if possible, coerce to the correct type.

How many alternatives have I suggested so far? Lets see...

1.  Implementing the *new* behaviour with a *new* operator.
2.  Some kind of pragma that makes all numeric literals default to
    float unless you explicitly suffix them.
3.  Some kind of pragma that becomes a permanent language option to
    change the division operator, but which never becomes compulsory.
4.  Some form of implicit type assertion attached to identifiers.

ANY of these could quickly and simply solve the problems that numeric
programmers are complaining about *without* breaking existing code.

Not bad for someone who doesn't believe any change is needed anyway.

>Reiterating why the current definition of '/' is evil: int and float
>together aren't really two distinct types: they are at most a
>type-and-a-half, and the integers are embedded in the space of floats

Tell that to a mathematician, or an engineer, or even an accountant -
all of these need to deal with inherently integer measures and
therefore using integer operations. Any of these people who have
Python scripts using division are going to have a problem.

You don't believe me about the accountants? - My current job is
software development for accountancy, and you don't use floats for
money believe me. £1.01 / 2 is 50p with 1p left over - there are times
when you count fractions of the smallest possible denomination, but it
certainly isn't the default.

Engineering - How would you feel if you knew a bridge was going to be
built with 2.5 supports on each side?

Mathematics - Mathemeticians practically *invented* integers, and note
that integers were understood thousands of years before fractions,
decimals or standard form.

Have you noticed how none of these groups consists of experienced
programmers?


You have a point of view - *not* an absolute undebatable fact. At the
end of the day, it's your language and you can do what you want - but
*please* think on it just a little longer.

-- 
Steve Horne
Home : steve at lurking.demon.co.uk
Work : sh at ttsoftware.co.uk



More information about the Python-list mailing list