Bug Hunt
You'll stop guessing and start narrowing, with a debugger, a stack trace and a log, until you can find a bug in under an hour.
About
Debugging is most of programming, and almost nobody gets taught it. The skill is narrowing things down: what do you know for sure, what's the smallest input that breaks, and where does reality stop matching the model in your head. Print statements are fine and a debugger is better. Random edits until it works aren't debugging, though, they're hoping.
At a glance
- Per requirement
- 25 XP
- Completion bonus
- 150 XP
- Requirements
- 6
- Takes
- One weekend
- Skill level
- Beginner (done it a few times)
- Cost
- Free
- Supplies
- Nothing special
- Where
- At home
- Other people
- On your own
Requirements
-
1
Read a stack trace from bottom to top and point to the line in your code that caused it. Take any error from one of your own programs. The bottom line is the actual failure, and the frames above it are how you got there. Find the first frame that's in your code rather than in a library. Take a screenshot of the trace with that line highlighted. Photo
-
2
Set a breakpoint, run to it, and inspect three variables. Your editor has a debugger built in, or you can use pdb, node inspect or dlv. Step over three lines and watch a value change as you go. Film a short clip of yourself stepping through with the variable pane visible. Video
-
3
Find and fix a bug in a program someone else wrote. Ask a friend for a broken script, or take a small program from a tutorial and have someone else plant a bug in it. Write down your hypothesis before you change anything. Take a screenshot of the fix as a diff, along with your written hypothesis. Photo
-
4
Shrink a failing case to the smallest input that still fails. If a 1,000-line file breaks the program, cut it in half. If it still breaks, halve it again, and keep going until it's three lines. The bug is usually obvious at that size. Take a screenshot of the tiny failing input. Photo
-
5
Add logging to a program and use it to find a bug without a debugger. Print or log at each step with the variable values, and add timestamps if you like. Then read the log like a story and find the place where it goes wrong. Take a screenshot of the log with the moment of failure marked. Photo
-
6
Write a one-paragraph post-mortem for one bug. Say what broke, why, how long it took to find, and what would have found it faster. Keep it honest, because the last line is the one that matters. Take a photo or a screenshot of the paragraph. Photo