Finding and Fixing a Mistake in a Plan
Byte the robot stands in a cozy kitchen, holding a recipe card and looking puzzled at a lumpy, lopsided pancake on the stove. Byte points with one finger at step three on the card, eyes wide with discovery.
- Explain what it means when a plan has a broken step.
- Identify which step in a short set of instructions caused something to go wrong.
- Describe what debugging means in your own words.
- Predict what will happen after the broken step is fixed.
Key terms
- plan
- a list of steps that tells you what to do
- bug
- a broken step that makes a plan go wrong
- debugging
- looking for a bug and then fixing it
- test
- trying the plan again to check the fix worked
Something Wrong Is a Clue
When you follow a plan and the ending is not what you wanted, do not feel upset. That surprise is actually a helpful clue. It tells you that one of your steps is broken, even before you know which one. A lumpy pancake or a still-dry plant is the plan waving a flag, saying look closer. Good problem solvers treat a wrong result as the start of a hunt, not as a reason to give up.
Checking One Step at a Time
Debugging means going through your steps slowly, one at a time. For each step you ask a simple question: did this step do what I expected? As long as the answer is yes, you move on. The first step where the answer is no is your bug. This careful, in-order checking beats guessing, because a plan can look fine overall while one hidden step quietly causes all the trouble.
Fix It and Try Again
Once you spot the broken step, you change it so it does the right thing, and you leave the working steps alone. But the job is not over until you try the whole plan again. Running it a second time proves the fix really worked. Even the best planners find bugs in their plans, so finding and fixing them is a normal and even fun part of building anything that follows steps.
Worked examples
Find the broken step in this thirsty robot plan.
- Step 1 picks up the cup, which works fine, so move on.
- Step 2 drinks the juice, which should make the robot not thirsty, but the robot is still thirsty, so this step did not work.
- Step 3 puts shoes on, which has nothing to do with thirst, so the bug is in step 2.
Answer: Step 2 (drink the juice) is the broken step, because drinking should end the thirst but did not.
Activity
Byte wants to make a sandwich but something went wrong! Tap the broken step to find the bug, then tap the fix to repair the plan.
Practice
A sandwich plan says to put the bread in your pocket; find and replace the broken step.
Tell a friend why we try the whole plan again after fixing a broken step.
Common mistakes to avoid
- A wrong result means start all over.You only need to find and fix the one broken step, not throw the whole plan away.
- After you change a step the plan is done.You should try the plan again to be sure the fix really worked before calling it finished.
Check your understanding
Byte follows a plan to water a plant, but the plant stays dry. What should Byte do first?
Byte fixed the broken step in a plan. What should Byte do next?
A robot follows these steps: 1 - Pick up the cup. 2 - Drink the juice. 3 - Put shoes on. But the robot is still thirsty! Which step is most likely broken?
Recap
When a plan gives a wrong result, that is a clue that one step is broken. Debugging means checking each step one at a time, asking if it did what you expected, until you find the bug. Then you fix that one step and try the whole plan again to make sure the fix worked.
Reflect
What is a plan of yours that went wrong, and how did you find the broken step?