PEP0238 lament

Skip Montanaro skip at pobox.com
Mon Jul 23 11:04:25 EDT 2001


    Tim> Why is that?  It's because unlike any other builtin arithmetic
    Tim> operation, "/" today can cause *catastrophic* loss of information
    Tim> silently, and in ordinary cases.  

Catastrophic is in the eye of the beholder.  I would find it just as
catastrophic if this

    x = len(somelist)/3

resulted in a floating point answer.  With integer division I haven't lost
anything, because if I want the remainder I can just execute

    y = len(somelist)%3

If I want to insure a floating point result I can just use the builtin
float.

I suspect that most people resistant to this change share the following two
traits:

    * a large body of code to maintain
    * most arithmetic they do in Python is non-scientific - implied by few
      imports of the math module in their code

I took a quick peek at my code.  Out of 360 Python source files, the math
module is imported just six times.  Two of those imports are in versions of
Digital Creations' DocumentTemplate module, which I didn't write, just
forked for private use, one was in a trivial test script, and one was a
spurious import (it was imported but not actually used).  That leaves two
files written by me that use math.  I only found calls to the float builtin
in 16 files.  I suspect that most people who are advocates of the change
proposed in PEP 238 either are numerical folks or don't have much code that
will break.  Numerical folks probably import math about as frequently as sys
and sprinkle their code liberally with calls to float().

S




More information about the Python-list mailing list