Plan Before Code
Ten minutes of planning saves an hour of confused typing. Use lists, sketches and trace tables before you open an editor.
- Pick the right planning tool for a task
- Review a plan with a partner before coding
- Revise plans when tests fail instead of patching randomly
Finish first
Topic contents
Lesson 1 of 3
Tools you already have
You now know three tools: break a task into steps, trace tiny programs on paper, and backtrack when choices fail. Planning means picking the right tool first.
A game level might need a sketch of states. A maths helper might need a trace table for formulas. A search problem might need a maze-style map.
Open the plan order lab. Watch a plan fail when steps are out of order, then see the fixed version succeed before you type any code.
Plan order
Watch a homework plan run in the wrong order and fail, then reorder steps so inputs come before outputs.
Plan order
Put steps in the right order before you startAverage three test scores
You wrote a plan before doing the job. Step through it like a robot would.
- 1.Print the average
- 2.Read score one, score two and score three
- 3.Add the three scores
- 4.Divide the total by three
Wrong plan
Printing the average first sounds fine in English, but the computer has no numbers yet. Order matters.
Lesson 2 of 3
Review with someone else
Swap plans with a classmate. Ask: is any step vague? Does order make sense? Could we trace the first ten lines together?
Teachers call this peer review. It is not cheating. It is how teams catch mistakes before they become bugs.
Keep plans short. One page beats ten. If the plan grows huge, your subtasks are probably still too big.
Lesson 3 of 3
When tests fail
Failing tests are clues, not insults. Read the expected against actual output. Trace the table to the line where values diverge. Update the plan, then update the code.
Random edits without a plan often create new bugs. Fix the idea first, then the typing.
You finished the problem solving pillar. Carry these habits into every programming class ahead.
Practice
Work these out yourself
No answer key here on purpose: these are the questions worth thinking through before you move on. Open one and work it out.
0/3 attemptedAssessment
Check your understanding
Answer each question, then read the explanation. That is where the learning is.
Finished this topic?
0 of 3 lessons marked done. Marking the topic complete ticks the rest.
