Debugging

Jan. 10th, 2013 10:29 am
jack: (Default)
[personal profile] jack
A step-by-step guide to debugging.

1. Do some simple checks and see if it was something obvious.
2. Make a list of everywhere the problem could conceivably be.
3. The bug will be somewhere in the difference between that list and reality.

OK, that's an exaggeration, sometimes the bug is where it should be, but sometimes it really is a matter of "what unexamined assumptions have I made, and which is most likely to be wrong?"

Date: 2013-01-10 10:54 am (UTC)
ptc24: (Default)
From: [personal profile] ptc24
Surely the results of step 2 depend on whether you're addressing that list to a rubber duck or not?

Date: 2013-01-10 10:56 am (UTC)
simont: A picture of me in 2016 (Default)
From: [personal profile] simont
Perhaps a better plan is to get somebody else to make a list of everywhere the problem could be! Because if you overlooked a possible cause of error when writing the code, there's a good chance you'll overlook the same one again in step 2, unless something has happened to change your thinking.

Date: 2013-01-10 01:51 pm (UTC)
gareth_rees: (Default)
From: [personal profile] gareth_rees
I know you're joking here, but still: trying to deduce the cause of the bug by pure reason should be your absolute last resort when all else fails! You should heed Richard Stallman in Debugging with GDB: "... the way we will find the bug is by running a single example under the debugger with breakpoints, not by pure deduction from a series of examples."

Date: 2013-01-10 08:52 pm (UTC)
catyak: Hedgehog in the grass (Hedgehog)
From: [personal profile] catyak
It's more irritating when you're looking for something that seems to have a one-in-four chance of failing on an overnight run and after several nights of test builds to narrow it down, the bug is (a) not where you thought it was and (b) is under a comment you left when putting in a fix for something else that, with hindsight, makes it bleeding obvious why it occasionally glitches.

D

Date: 2013-01-13 01:29 pm (UTC)
From: [identity profile] eudoxiafriday.wordpress.com
I am at a much, much lower level of programming-fu than you, and the most recent debugging tip I learnt was "see if your code is actually being run" ... which I suppose is somewhere in the category of "see if it was something obvious". Having spent a couple of hours wondering why nothing I tried made a difference ... yeah. Oops. On the bright side, I probably won't do that again! (The file I was working on was needed by someone else, so I copied across what I was working on to another file and worked on that one but forgot to copy the bit that actually *called* the method ...)