Why fixing bugs is better than writing code
Monday 5 January 2026

Shifting the focus from syntax to logic in the IB Computer Science classroom.
We have all been there. You introduce a new programming concept like while loops, and give your students a blank screen and a prompt: "Write a program that counts to ten." Five minutes later, half the class is staring at a blinking cursor, and the other half has written print("1, 2, 3, 4...").
When we ask beginners to write code from scratch, we are asking them to do three difficult things simultaneously:
- Recall Syntax: Remembering where the colons and parentheses go.
- Structure Logic: figuring out the algorithmic steps.
- Solve the Problem: Apply that logic to the specific task.
It is often too much. The result? Frustration, copy-pasting, and very little actual learning.
The Bug-Fixing approach is often a better way to develop skills and computational thinking. Instead of asking students to build, ask them to repair. By giving students code that is syntactically correct but logically flawed, we strip away the stress of syntax errors. They don't have to worry about missing semicolons or indentation.
Instead, they can focus entirely on the Computational Thinking:
- Tracing: "What does this variable actually hold right now?"
- Logic: "Why is the loop stopping at 9 instead of 10?"
- Debugging: "How do I fix it?"
This approach mirrors the real world. Professional developers spend far more time reading and debugging code than they do writing new functions from scratch.
Here is a resource I successfully used last term to introduce Topic B2.4 (Algorithms). It covers the Bubble Sort, a classic algorithm that students often memorise but rarely fully understand.
The code below runs without crashing, but it doesn't sort the list correctly.
- The Goal: Find the logic error.
- The Hint: Look at the inner loop range.
Why This Works: This simple exercise forces students to trace the swap logic. They quickly realise that arr[j] = arr[j+1] overwrites the data before it can be saved. They have to "invent" the temporary variable solution themselves. That "Aha!" moment is far more potent than copying a perfect algorithm from the board.
We have developed a full suite of these "Broken Code" Challenges covering Topic B2.
Subscribers can access the full interactive pack, complete with solution keys and teacher notes, on each main sub-topic page:
B 2.1 Programming Fundamentals
Stop teaching syntax. Start teaching logic.