Debugging strategy?

Tim Peters tim_one at email.msn.com
Tue Aug 1 15:47:13 EDT 2000


If you use try/except, make very sure you're not suppressing any errors you
didn't intend to suppress.

If the algorithm was using ints instead of longs by accident somewhere, and
you're not using try/except, Python would have screamed at you (by raising
OverflowError) if ints weren't "big enough" to hold your results.

There are no known bugs in Python's long int routines, and indeed they
haven't been changed in years.  "trillions" is actually small compared to
what people usually use Python's longs for.

As a general clue, when errors pop in "big" problems that didn't show up in
"short" ones, it's often simply the case that the "big" problem caused an
unusual path through the code to be taken, and there's a bug on that path.
You *should* have a collection of small test cases that guarantees to
exercise every possible path through your code.  In general, the more "if"s
in the code, the less effective "random" small tests will be.

All in all, sounds like you're in for a lot of pain <wink>.

> -----Original Message-----
> From: python-list-admin at python.org
> [mailto:python-list-admin at python.org]On Behalf Of Duncan Smith
> Sent: Tuesday, August 01, 2000 3:28 PM
> To: python-list at python.org
> Subject: Debugging strategy?
>
>
> I have a directed tree structure (possibly a forest).   A weight (long
> integer) is associated with each vertex.  I can permute the structure
> locally and calculate the new (local) weight and thus the overall
> weight of
> the tree.  The goal is to minimise the overall weight.  The vertex weights
> can be very large (trillions).  I am currently using simulated annealing,
> which works fine for most trees.  But occasionally, for larger trees,
> something goes awry and I find that either the tree has not been permuted
> correctly, or the weight has not been calculated correctly (I suspect the
> former).  There is no apparent reason why this should be more likely to
> occur for larger trees and I'm pretty confident my scheme is O.K.
> on paper.
> I've tried reproducing the fault on small trees without any luck.
>
> The problem is that I don't know how to go about debugging my
> code when the
> problem arises so infrequently; possibly on the 20,000th iteration of an
> algorithm.  Has anyone any idea how I might tackle this problem?  Does it
> sound characteristic of a particular type of coding error (bearing in mind
> I'm no computer scientist)?  Might I be running into problems with using
> such large integers (I've checked that they remain long integers
> throughout
> the permutation scheme)?  I'm not expecting anyone to find the bug for me
> because following my code would require a much more detailed
> explanation of
> the permutation scheme and/or the full 50+K of code.  But I would
> appreciate
> any advice.  Thanks in advance.
>
> Duncan Smith
>
>
> --
> http://www.python.org/mailman/listinfo/python-list






More information about the Python-list mailing list