Part 3 · Running Your First Code Experiments · Chapter 11
Bugs Are Just Surprise Data!
Reframing Errors into Clues, Reading Telemetry, and the Bug Detective Mindset
"The most exciting phrase to hear in science, the one that heralds new discoveries, is not 'Eureka!' but 'That's funny...'"
— Isaac Asimov
The mystery
The Day the Screen Turned Crimson
It happened at 2:14 PM on a Thursday.
The Computational Laboratory had been peaceful for nearly two hours. The only sounds were the soft hum of cooling fans, the rhythmic click of the keyboard, and Agent Spark gently humming an 8-bit lullaby while organizing digital simulation records.
Then, without warning, the terminal monitor flashed a terrifying, violent shade of crimson red.
A loud digital claxon sounded through Spark’s audio synthesizer: BUZZZZZZT!
Across the central display screen, thirty-five lines of dense, jagged computer text cascaded downward at breakneck speed:
Traceback (most recent call last):
File "mars_explorer.py", line 142, in autonomous_navigate
turning_angle = target_vector / distance_to_wall
ZeroDivisionError: division by zero
🚨 SYSTEM HALTED. FATAL EXCEPTION CODE 0xDEAD.
Agent Spark immediately did something extraordinary: it retracted all six of its sensor antennas into its titanium chassis, shut off its cheerful blue status lights, and dropped like a lead bowling ball directly onto a padded laboratory stool.
Its circular LED eyes flickered in a panicked shade of dull maroon.
"Chief Scientist!" Spark whimpered, its synthesized voice trembling with robotic grief. "It has occurred. The end of our research career. I have executed an illegal mathematical division. I have divided a number by the forbidden numeral zero. The fabric of mathematical spacetime has ripped in half. I am defective. Please unbolt my memory core and donate my titanium chassis to a local toaster factory."
The Chief Scientist slowly turned around in their rolling swivel chair, looked at the crimson screen, and then looked at Spark huddled in a sad ball on the stool.
The Chief Scientist took a deep breath.
And then, the Chief Scientist threw both hands into the air and let out a giant, roaring cheer:
"WOOHOOOOOOOO!"
Spark’s antennas poked back out in shock. "Chief Scientist? Have your biological audio receptors malfunctioned? The screen is covered in red blood-text! The rover crashed into a virtual boulder!"
"Spark!" the Chief Scientist yelled, grinning from ear to ear. "Raise your right mechanical manipulator into the air right now!"
Spark hesitated, cautiously raising one robotic arm.
SMACK!
The Chief Scientist gave Spark a thunderous, high-energy HIGH FIVE!
"What was that kinetic collision for?" Spark asked, rubbing its metallic palm.
"That was our laboratory celebration ritual!" said the Chief Scientist, pulling up a rolling stool beside Spark. "Listen to me very carefully, Agent Spark: In this laboratory, a crash is NOT a failure. A computer error is NOT a bad report card. An unhandled exception does not mean you are stupid, or that I am stupid, or that anyone should become a toaster."
"Then what is it?" Spark whispered.
"It is a gift," the Chief Scientist smiled, pointing directly at the red text. "It is the universe tapping us on the shoulder and saying: 'Hey, look over here! You assumed the distance to the wall would always be a positive number, but the rover just discovered a situation where the distance was exactly 0.000!' In our laboratory, crashes have an official name: SURPRISE DATA!"
THE TWO WAYS TO LOOK AT A BUG
┌──────────────────────────────┬──────────────────────────────┐
│ THE TRADITIONAL ANXIETY │ THE CHIEF SCIENTIST MINDSET│
├──────────────────────────────┼──────────────────────────────┤
│ 1. Red text = "I am bad." │ 1. Red text = "A free clue!" │
│ 2. Panic & close the editor │ 2. High-Five celebration! │
│ 3. Wildly guess at code lines│ 3. Inspect the 3 Clues │
│ 4. Lose confidence │ 4. Formulate new hypothesis │
│ 5. Give up │ 5. Grow smarter! │
└──────────────────────────────┴──────────────────────────────┘
Spark’s LED eyes shifted from dim maroon back to bright, luminous turquoise. "Surprise Data? A clue left behind by the universe?"
"Precisely," said the Chief Scientist. "And right now, you and I are not programmers apologizing for a mistake. We are Bug Detectives. Put on your detective hat, Agent Spark. The investigation begins now!"
Unplugged lab
The Blind Maze Navigator
Before we dissect Python stack traces, let's play a physical game that reveals why computers run into walls and how "crashes" provide the exact telemetry needed to solve any maze.
Figure 11.1: The autonomous exploration rover stops before a barrier in the sensor maze; Agent Spark displays diagnostic telemetry distance graphs to investigate the crash clue.
Laboratory Equipment Needed:
- A Collection of 6 to 10 Hardcover Books or Cardboard Boxes (to build maze walls on a tabletop or floor).
- 1 Toy Car or Small Action Figure (The Exploration Rover).
- 1 Blindfold or Scarf (or simply close your eyes).
- 1 Metric Ruler or Measuring Tape.
- 1 Lab Pencil & The Bug Detective Investigation Sheet.
Step-by-Step Experimental Setup
THE LIVING MAZE LAB
════════════════════════════════════════════════════════ Wall A
▲
│ Path 1: Move forward 30 cm
│
[ ROVER ] ──► Turn Right 90° ──► Path 2: Move forward 40 cm
│
▼
════════════════════ Wall B
Step 1: Construct the Labyrinth
Great minds of the lab
Grace Hopper and the World's First Bug
To understand why we call software errors "bugs," and why diagnostic error messages exist at all, we have to travel back to September 9, 1947, at Harvard University in Cambridge, Massachusetts.
World War II had just ended, and researchers were working on one of the most powerful computers on Earth: the Harvard Mark II Aiken Relay Calculator.
The Mark II was not a sleek smartphone that fit in a pocket. It was a monstrous, room-sized machine stretching over fifty feet across, containing thousands of electromagnetic clicking switches called relays. Whenever the computer calculated a number, thousands of metal relay fingers slammed shut with a rhythmic clatter that sounded like a room full of galloping mechanical horses.
THE HARVARD COMPUTING LAB
September 9, 1947
┌─────────────────────────────────────────────────────────┐
│ HARVARD MARK II RELAY COMPUTER │
│ │
│ Panel A Panel B Panel C Panel D Panel F │
│ [#####] [#####] [#####] [#####] [ 🚨#70 ] │
│ │
│ "Relay 70 on Panel F refused to close! │
│ Calculations ground to a halt!" │
└─────────────────────────────────────────────────────────┘
On that warm late-summer afternoon, the machine suddenly jammed. Relay number 70 on Panel F refused to close its electrical contact. The computer’s calculation halted.
Inside the laboratory was a remarkable 40-year-old mathematician, naval lieutenant, and computing pioneer named Grace Brewster Murray Hopper (1906–1992).
The Tweezers and the Moth
Digital sandbox
The Sensor Maze Rover
Now let's bring Grace Hopper's investigative mindset into our digital proving ground.
Open our companion simulation from web_minigames/04_sensor_maze/index.html or our Python sandbox at sandboxes/chapter_11_sensor_maze_debugger/telemetry_debugger.py.
In this laboratory, you are the Lead Telemetry Engineer for an autonomous planetary exploration rover equipped with front-facing distance sensors.
THE AUTONOMOUS ROVER PROVING GROUND
Front Distance Sensor
))))))
┌───────▼───────┐
◄─────── │ [ ROVER ] │ ───────► Wall Barrier
Left └───────────────┘ Right [█████]
Sensor Sensor [█████]
[█████]
Telemetry Controls:
1. Speed (speed_cm_s): How fast rover travels
2. Braking Threshold (braking_threshold_cm):
Safety distance at which brakes engage
The Physics of Reaction Time
Why do autonomous vehicles—from Mars rovers to self-driving cars—crash into obstacles?
It is rarely because the software is "broken." It is almost always because of a mismatch between Sensor Sampling Rate, Speed, and Reaction Distance:
Deep dive · Ages 10+
Python Under the Hood
Let’s look at how telemetry logging is built in production aerospace systems.
When NASA flies a rover like Perseverance on Mars, there is a 20-minute radio communication delay to Earth. Engineers cannot watch with a joystick. If a wheel slips or a sensor glitches, the rover writes every millisecond of sensor telemetry into a black-box buffer.
Here is the complete code from sandboxes/chapter_11_sensor_maze_debugger/telemetry_debugger.py:
Chapter 11 Key Concepts Review
- Bugs Are Surprise Data: An error is not a personal failure; it is empirical feedback revealing an unhandled condition or edge case.
- The Harvard Mark II Moth: In 1947, Grace Hopper taped the first physical computer bug into her logbook, forever naming software glitches.
- Grace Hopper's Compilers: Hopper invented programs that translate human words into machine language and return diagnostic error messages.
- The 3 Detective Clues: Every error message tells you Where (line number), What (exception type), and Why (offending value).
- Telemetry Buffers: Recording sensor frames over time allows engineers to reconstruct and solve crashes long after they occur.
Congratulations, Chief Scientist! You have completed Part 3: Running Your First Code Experiments! In Part 4, we step into the advanced arena: building playable mini-games, conducting enterprise A/B tests, and unlocking the mathematics of fun!
Like what you see?
Register for free to run the experiments, make predictions and solve the bug-detective cases. Your work is saved on your device and syncs to your account.