Future division patch available (PEP 238)

Steve Horne sh at ttsoftware.co.uk
Mon Jul 23 06:26:03 EDT 2001


On 23 Jul 2001 10:33:08 +0200, Martin von Loewis
<loewis at informatik.hu-berlin.de> wrote:

>Stephen Horne <steve at lurking.demon.co.uk> writes:
>
>> Division on integers should be integer division. 
>
>I don't think there is any argument about that: the only question is
>how to spell integer division; in the future, it will be spelled '//'.
>
>> Mathematically, integer division should be the inverse of integer
>> multiplication, with no extra functionality bar the need to allow for
>> the remainder. Well shock horror - that's exactly what we've got now
>> and exactly what we're throwing away.
>
>We are not - we are just spelling it differently. However, if you
>think that the inverse of multiplication on integers should be spelled
>'/' (even though the integers do not form a group with respect to
>multiplication), you could still get this under the new PEP. It would
>be possible to implement
>
>12/4 is 3 (not 3.0)
>14/4 == 3.5

Yes, but what about my existing algorithm in some code somewhere that
uses n / 2 to partition an array and checks for == 0 as the
termination condition. It's not exactly going to work very well after
the change, is it.

The point of telling people that integer division is important is to
make them aware of the impact of breaking all the existing code that
uses it - if this goes ahead, Python is going to be a joke.

The view that integer operations should be closed on integers, and
that an separate division operator for integers is going to be at
least as confusing to newbies - not to mention the confusion to
experienced programmers - is a separate issue, a matter of opinion,
even though in my case it is a very *strong* opinion.

>> Integer division is important to a huge range of applications -
>> anything involving money stands out as the obvious case, but also
>> cryptography and others.

But the existing use of division in many applications is going to
suddenly work differently, leading to all kinds of strange
hard-to-trace bugs, and Pythons advocates are going to end up looking
*very* stupid indeed.

It's the kind of thing that could make many of Pythons strongest
supporters say "sod this for a lark, I can live without the ground
shifting under my feet, Perls syntax might be naff but at least the
programs still work from one release to the next"

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



More information about the Python-list mailing list