Lesson 2 · Computational Thinking
Narrowing down where it went wrong.
When something breaks, the instinct is to read the whole thing from the top, hoping the mistake jumps out.
It rarely does. On anything longer than a few lines, staring is the slowest possible method.
The professional approach is to narrow down where the bug lives before trying to see it. You don't need to spot the mistake — you only need to work out which half of your instructions it's hiding in. Then which half of that.
You met this idea in Chapter 2 with the phone book, and it's the same trick.
Check the middle of your algorithm. Is everything still correct at that point?
Repeat. Twenty steps become ten, then five, then two. Five checks find a bug in thirty steps. Reading from the top would take thirty.
5 more parts in this lesson
Walkthroughs, code labs, mini-games and the checkpoint quiz unlock when you buy the course.