PEP0238 lament

Tim Peters tim.one at home.com
Mon Jul 23 00:16:19 EDT 2001


[Tim]
> Not all experienced programmers agree.  At the last Python Conference, I
> moderated a ... group discussion ... By show of hands, about 3/4ths of
> the participants agreed that 3/4 should not return 0, but rather
> *something* x such that x*4 had a better chance of being confused
> with 3 than with 0.

[John W. Baxter]
> I see a fairly strong argument there for starting out with a language
> in which int / int --> float (or rational) and int // int --> int (or
> int div int --> int).

I don't consider a vote an argument.  At best, since it was a visible show
of hands, it let everyone know who wasn't worthy to live due to voting the
wrong way <wink>.

> I don't see it as a strong enough argument

It's not an argument at all -- it was in response to Arther asking whether
experienced programmers would favor such a change (and, yes, some would).

> to overcome the fact that the careful programmer will have to inspect
> every / in all the code, before installing 2.3 or whatever version
> this happens in, to see whether (a) it IS division, as opposed to
> the / in  '<a href="6/7.html">'  (that's contrived...but possible)

Guido suggested building a tool on top of the tokenize module; it reliably
distinguishes "/" as an operator from all other occurrences of "/"; no false
leads.

> and if so whether it has to be respelt as // (or div).

I probably use integer division more than most, and that job looks trivial
to me -- but then I *understand* my algorithms, and "it's obvious" in each
case which I intended.  If this happens, the transitional release should
also produce runtime warnings pinpointing lines where "/" is applied to
integer arguments, so if you've got good unit tests nothing will be missed.

> Some of them will; some won't:  some of both outcomes indicate latent
> errors in the code, so the inspection isn't completely wasted after
> all.
>
> And it may not be her code...she could be 3 or 4 people removed from
> the creator, who is gone.  [Another good thing about finding the latent
> errors.]
>
> It's true--as stated elsewhere--that Guido hears all the complaints.
> It's also true that until recently there was no reason for Guido to
> hear "Guido, thank you for defining int / int to be integer division,
> because integer division is natural for my problem space."  So he's
> been getting a biased sample.  Probably a fairly representative one
> even so.

Don't forget that this has been debated repeatedly over the course of
several years.  Most people drop out of these things after the fifth time
<0.5 wink>.

what-i-can't-tolerate-is-making-division-case-sensitive-ly y'rs  - tim





More information about the Python-list mailing list