DebuggingJohn Graham-CummingSeptember 2013
Ada Lovelace (1840s)
Maurice Wilkes (1950s)As soon as we started
programming, we found to our surprise that it wasn't as easy to get programs right as we had thought. Debugging had to be discovered. I can remember the exact instant when I realized that a large part of my life from then on was going to be spent in finding mistakes in my own programs.
Writing code is hardBut writing bugs is easy!Everyone does it all the time
without even thinking about it.
Estimates in GOOD code there are 2 to 4 defects per 1,000 lines
You’re not that goodYou will spend many hours
debugging
ProgrammerIf a person who debugs code is a
debugger than a person who writes the bugs must be a... bugger?
Always have a fighter pilot in your presentation
Colonel John Boyd
OODA Loop
THE GREATEST DEBUGGER YOU WILL EVER USE IS IN YOUR HEAD
Ignore your tools!
ESSENTIAL SKILL: RUN CODE IN YOUR HEAD
RISEReproduceIsolateTargetExcise
Reproduce
IsolateTighten the OODA loop
◦The smallest◦Fastest◦Most easily repeated
And automate itThen turn it into a test case
Target
ESSENTIAL SKILL: ALWAYS BE ASKING WHY
Debugging Christmas Lights
ESSENTIAL SKILL: DOUBTING
ExciseFix the bugDon’t introduce new bugs!
You can check this with the test case that you made earlier
Talk to the teddy
Look Around DebuggingWhere there’s smoke...... research shows that bugs tend
to cluster
When you fix a bug look for more in the same spot.
5 bugs in a single linedir.permissions = 666; // Make the file writable
Bug 1: updates permissions without asking
Bug 2: doesn’t make the file writable
Bug 3: creates security holeBug 4: used decimal not octalBug 5: comment is incorrect
Remember This One Thing!The most effective debugging
tools are: your brain, a unit test, and the print statement.