Boss lesson · Unit 03
The bug that hides
Halve the suspects: in the code, the input and the history
What you practise
- Binary search for a bug: in the input, in the code path with prints or a debugger, in history
- Rubber-ducking
- Off-by-one, mutation and aliasing bugs traced end to end
Try a question from this lesson
Pick one
One step of an 8-step pipeline is broken: right input, wrong output. A print after any step shows if the data is still right. How many prints always find the step?
Hint
Print in the middle first. How many suspects are left after that?
Correct answer
3
Why
Print after step 4: the bug is in the first half or the second. Then halve again, and again: 8, 4, 2, 1. It is binary search with steps instead of numbers.
The idea
Concept cards are short on purpose. In the app they appear between questions, after you have met the idea.
Concept
Bisect everything
Debugging is a search. If you know one state that is good and one that is bad, check the middle, and half the suspects are gone.
It works on the code path: print halfway. It works on the input: delete half. It works on history: test the version halfway between the last good one and the first bad one.
11 more exercises in the app
- 3× type the answer
- 5× multiple choice
- 1× fill the blanks
- 1× order the lines
- 1× match the pairs
Bitpath is an iOS app in development. Join the waitlist and you get one email when it is ready to try.