Problem Solving — CS & DS

Lecture 07 — Debugging as a Method

Learning objectives

Case-based lecture: you attempt, we discuss, then we reveal.

Today

The plan

Key definitions

Key definitions

Explain each in one breath; the cases will do the heavy lifting.
Worked example

The missing first item: reproduce, hypothesise, isolate

cs-025

Items [2.00, 3.50, 1.25] print a receipt of 4.75 instead of 6.75. Debug it by the method: reproduce, hypothesise, isolate, fix, verify.

Expected: 4.75 6.75

Cost: Debugging cost, not runtime: one repro, one minimal input, one rerun. The method's value is that it terminates.

Worked example

The ghost duplicate: aliasing proved by identity

cs-027

A task board shows one task list twice after a second edit. Prove the cause and fix it.

lines = ["a", "b"]
echoed = []
for i in range(len(lines)):
    echoed.append(lines[i])
print(len(echoed), echoed[0])

Expected: duplicated rows with identity True; after the fix the rows differ and the check is False

Cost: O(k) extra per call for the copy - correctness buys the copying cost.

Case attempt · lecture 07
Case cs-025 · Beginner

The Case of the Missing Sales

A receipt program prints a total that is too low by exactly one item's price. Form hypotheses, design the minimal reproducing input, and localise the fault.

⏱ 5 minutes — attempt now

Pseudocode, flowchart or Python. State one assumption. Compare with your neighbour at minute 4.

Discussion

cs-025 — discuss

Instructor: the reveal, the reasoning section and common wrong turns are in the instructor distribution for cs-025 — not embedded in this deck.

Case attempt · lecture 07
Case cs-026 · Foundational

The Off-by-One Invoice

An invoice tool includes one extra row under specific conditions. Use bisection over input shapes to find the boundary condition that triggers the defect.

⏱ 5 minutes — attempt now

Pseudocode, flowchart or Python. State one assumption. Compare with your neighbour at minute 4.

Discussion

cs-026 — discuss

Instructor: the reveal, the reasoning section and common wrong turns are in the instructor distribution for cs-026 — not embedded in this deck.

Case attempt · lecture 07
Case cs-027 · Intermediate

The Ghost Duplicate

A task list occasionally shows one task twice after edits. Reason about shared references / aliasing as the cause and design the experiment that proves it.

⏱ 5 minutes — attempt now

Pseudocode, flowchart or Python. State one assumption. Compare with your neighbour at minute 4.

Discussion

cs-027 — discuss

Instructor: the reveal, the reasoning section and common wrong turns are in the instructor distribution for cs-027 — not embedded in this deck.

Case attempt · lecture 07
Case cs-028 · Advanced

The Heisenbug

A defect that disappears when a debug print is added. Discuss causes (ordering, mutation during iteration, hidden dependency) and design a strategy to catch it.

⏱ 5 minutes — attempt now

Pseudocode, flowchart or Python. State one assumption. Compare with your neighbour at minute 4.

Discussion

cs-028 — discuss

Instructor: the reveal, the reasoning section and common wrong turns are in the instructor distribution for cs-028 — not embedded in this deck.

Check yourself

Common misconceptions

Summary

Summary & exit question

Exit question (choose one, 60 seconds)

  1. Order the clinic protocol steps.
  2. Why fix nothing before the hypothesis is confirmed?
  3. What is a regression test for?
Expected answers (instructor): reproduce, hypothesise, cheapest experiment, isolate, fix, re-test unconfirmed fixes destroy the evidence and add new defects to make a fixed defect fail permanently if it ever returns
→ / space: next · ←: back · Home/End: jump · Ctrl+P → PDF