Blog by Sumana Harihareswara, Changeset founder
A Debugging Afternoon
Hi, reader. I wrote this in 2014 and it's now more than five years old. So it may be very out of date; the world, and I, have changed a lot since I wrote it! I'm keeping this up for historical archive purposes, but the me of today may 100% disagree with what I said then. I rarely edit posts after publishing them, but if I do, I usually leave a note in italics to mark the edit and the reason. If this post is particularly offensive or breaches someone's privacy, please contact me.
Yesterday I helped a friend debug her Python code. I had never seen it before.
She was nearly finished with a huge project refactoring a code base new to her, and had gotten all but one of the ~200 tests to pass. And the test behaved differently whether it ran by itself or in the suite.
I reminded her that
pdb lets you make breakpoints and use
c to continue between them, so you don't have to step through every single line (see "A few things to try while debugging" in my presentation "A Few Python Tips"); wondered with her about whether we were facing a failure of idempotence; brainstormed with her about possible timing problems and race conditions; suggested she use a sort of binary search to track down the specific interaction between the failing test and the other tests in the suite; asked her whether she could replicate this behavior in a fresh virtual environment with freshly installed dependencies; gently nudged her to systematically keep track of the hypotheses she was testing.
I tossed out hypotheses to check (maybe the test's
tearDown() step is not actually removing everything from the collection; maybe it is not flushing the overflow queue; maybe there is a significant difference between the
tearDown() for this test and for others).
She fixed it, and we celebrated. She should feel proud of tracking down and fixing a gnarly bug. I feel proud that I substantially helped a professional engineer debug a hard problem. Sometimes I said "This is just based on intuition and pattern-matching, but what if..." and I was right. My gut is worth listening to. That's good to know.