/en-tutor-prep-s4-ict-debugging-version-control/
/en-tutor-prep-s4-ict-debugging-version-control/
General Inquiry: info@TutorZone.com.hk
Office Hours: Monday to Saturday - 9:00 AM to 6:00 PM
WhatsApp Monday to Sunday - 24 hours
Hotline: +852 6828 1809
Instant Support: +852 9061 3106

S4 ICT: Debugging and Version Control (three error types, binary-search debugging, commits and rollback) Tutor Prep Guide with a 45-minute plan, teaching script and common errors

S4 ICT: Debugging and Version Control (three error types, binary-search debugging, commits and rollback) Tutor Prep Guide with a 45-minute plan, teaching script and common errors

  • 2026-11-15

Students add prints from the first line whenever something breaks, and cannot say how many attempts that costs. This lesson turns debugging into three error types plus binary search, and shows why version control is a safety net.

Objectives — By the end of the lesson students can: (1) say when each of the three error types surfaces, which tool reports it and how it is caught; (2) find one bug in 600 lines by binary search and prove with powers of two that 10 steps suffice, since 512 is too few and 1024 enough; (3) turn 114 passes out of 120 unit tests into 95 per cent and explain why the whole suite is rerun after any change; (4) describe commits, branches, merge conflicts and rollback, and read a diff of 40 lines added against 15 removed as a net 25.

01 Prerequisites (3-minute check)

If any of these fails, fix it before the lesson starts.

Skill Quick check Pass mark
Powers of two Which power of two exceeds 600 10, since 1024 does
Percentages 114 passes out of 120 tests: the pass rate 95 per cent
Addition and subtraction A diff adds 40 lines and removes 15: the net change A net 25 lines added
Division 12 commits at 3 a day: how many days 4 days

02 Lesson flow (45 minutes)

Time Stage Tutor does Student does
0-6 min Entry check Ask for the power of two above 600, 114 over 120, the net of 40 and 15, and 12 over 3; keep the answers on the board Spoken answers, working on paper
6-16 min Act one: three error types, three ways to hunt Three columns for syntax, runtime and logic, each with when it surfaces and who reports it Students say a logic error runs to the end but gives a wrong answer
16-26 min Act two: binary search, 600 lines in 10 steps Print a variable at the midpoint or set a breakpoint, halving the range each time; write 512 too few and 1024 enough Students compute 10 steps
26-36 min Act three: regression testing and version control 114 of 120 is 95 per cent; 12 commits at 3 a day is 4 days; a diff of 40 and 15 nets 25 Students say which commit a rollback should target
36-42 min Question types with changed numbers Switch to 900 lines and 138 passes out of 150, then run the four question types Students do one and write the unit (steps, per cent, lines)
42-45 min Exit check Three spoken questions; note which act each error comes from All three correct

03 Teaching script (read it out)

Scene 1: Act one: three error types surface at three different moments

Errors come in three kinds and each is hunted differently. A syntax error, a missing bracket, a stray colon or a misspelt variable, is reported at once by the interpreter or compiler, so the program never even runs and the message carries the line number. A runtime error happens halfway through a run: division by zero, an index out of range, opening a file that does not exist. It only appears when the right input arrives, which is why it can hide for weeks. A logic error is the quiet one: the program runs to the end with no message at all and still gives the wrong answer, for example computing the mean as the total divided by n minus 1. Only one method catches it, comparing the actual output with the expected output. So when a student says there was no error message, all that is proven is that there is no syntax error.

A program runs to completion and computes the wrong total: which error type is it, and how would you prove it wrong?

Scene 2: Act two: binary search turns 600 lines into 10 steps

To find a logic error in 600 lines, printing line by line is the slowest method available: 600 lines means up to 600 attempts. Binary search halves the suspect range each time. Print the key variable at line 300; if the value is already wrong the fault lies in lines 1 to 300, otherwise in 301 to 600, then halve again. How many steps? Two to the ninth is 512, which is below 600, so nine is not enough; two to the tenth is 1024, which covers it, so ten steps locate a single line. A breakpoint with step execution is the same idea as a tool: stop on a line, watch the variables, step one line at a time, and no code changes are left behind to clean up. In a written exam the reasoning to write down is still halving.

How many halvings does 900 lines need, and why is one print at the midpoint not enough?

Scene 3: Act three: regression testing and version control are two sides of one idea

Debugging ends with proof that nothing else broke, which is regression testing. Of 120 unit tests, 114 pass, so the pass rate is 114 over 120, 0.95 or 95 per cent, leaving 6 to fix, and the whole suite is rerun after every change because one edited line can break ten others. Version control is the infrastructure for that rerun and for rollback. A commit is a meaningful save point: at 3 a day, 12 changes take 4 days. Branches let a feature be tried without touching the main line, and a merge conflicts when both sides edit the same line, forcing a human choice. Rollback restores files to an earlier commit, which only works if each commit is small; roll back a fat commit and good changes vanish with the bad. A diff is the difference between two versions: 40 lines added and 15 removed is a net 25, not 55.

If one commit changes five things and one of them turns out to be buggy, what does a rollback cost you?

04 Question types and worked steps

Type Example Steps Answer
Classify the error The program runs but the answer is wrong Three questions: any message, when it appears, is the answer right Logic error: runs, no message, wrong answer
Design the debugging steps 600 lines, only input and expected output known Compare expected with actual, halve the range, then use powers of two for the count At most 10 steps, since 1024 covers 600 and 512 does not
Compute the pass rate 114 of 120 unit tests passing Passes over total times 100; subtract for the remainder 95 per cent, 6 still failing
Describe version control 12 commits at 3 a day, two versions back Commits divided by per-day pace; rollback names the target commit 4 days; rollback restores the files to that commit
Sanity check (teach this): Four checks: (1) a syntax error always comes with a message and a line number, so an error with no message is never a syntax error; (2) verify the binary-search count with powers of two, since 512 is below 600 so nine fails and 1024 so ten works; (3) a pass rate never exceeds 100 per cent, and 114 over 120 is 0.95; (4) the diff net is what remains after adding and removing, so 40 plus 15 is 55 but the net change is 25.

05 Independent practice (3 questions)

Question Answer What to watch
114 of 120 unit tests pass: what is the pass rate 95 per cent Watch for 6 used as the numerator
Finding one bug in 600 lines by binary search: how many steps at most 10 Verify with powers of two: 512 short, 1024 enough
A diff adds 40 lines and removes 15: the net change 25 lines added Do not add 40 and 15 together

06 Common mistakes and what to say

Mistake Student writes Say this
Treating a logic error as a syntax error Answering that with no red message the program is correct and the input must be wrong A syntax error stops the program before it runs; a logic error runs fine and returns a wrong answer, caught only by comparing with the expected output. Confusing the two leaves students stuck at it compiles, so it ships.
Printing every line instead of halving Adding a print to each of the 600 lines, so 600 attempts Binary search halves the range, so 600 lines take at most 10 steps; line-by-line takes 600, which no exam allows.
Skipping the test suite after a fix Declaring the task done once the one failing feature works, without rerunning the tests Regression testing exists to prove that fixing one line did not break another. Skip it and the new defect ships, usually harder to trace.
Stuffing every change into one commit Putting three unrelated edits into a single commit Commits should be small and single-purpose so a rollback is precise. A commit holding ten changes rolls back the good ones with the bad.

07 Homework (paper, section and question numbers)

08 Exit check (last 5 minutes)

Question Answer Decision
The program runs but the answer is wrong: which error type Logic error, caught by comparing with expected output Wrong: reteach act one, when each type surfaces
Finding one bug in 600 lines by binary search: steps at most 10, since two to the tenth is 1024 Wrong: reteach act two, verify with powers of two
One commit changes five things and one is buggy: what does rollback cost It removes the good changes too, so commits must be small and single-purpose Wrong: reteach act three, commit granularity

09 Tutor FAQ

How does this connect to S3 Python loops and functions?

S3 teaches writing a working program; this chapter teaches finding faults in it. A wrong loop repeats its mistake a thousand times, which is exactly where binary search and tests earn their place.

Is 45 minutes enough for three error types and version control?

Yes, if act one takes only ten minutes. Three columns and one line about timing settle the error types, and the time belongs to the binary-search arithmetic in act two.

Are 120, 114 and 600 real project figures?

No, they are teaching numbers chosen to divide cleanly. Real test counts and debugging times vary widely, and the method and direction of judgement are the point.

Find a tutor — freeTutor Registration →

A TutorZone lesson-prep guide. Written by the TutorZone team; questions and lesson flow are original and are not taken from any school or publisher material.

© TutorZone · www.tutorzone.com.hk · For personal study and teaching use only.

Join as a tutor or coach — academic, music, sports, arts, STEM. Free to register. See how it works →