Computer engineeringLevel 3 · Innovator
Testing and debugging
Code that runs is not the same as code that is right. Syntax errors stop a program before it starts, runtime errors such as dividing by zero raise an exception with a traceback, and logic errors quietly give the wrong answer. A traceback is read from the bottom up: the last line names the error and the lines above show where it happened. Tests are small checks, such as assert statements, that compare a function's output with answers worked out by hand, including edge cases like an empty list, zero or a negative value. Debugging is a method rather than guessing: reproduce the fault, form a hypothesis, test it with a print or a smaller input, fix it, and keep the test so the bug cannot quietly return.
Why it mattersA unit-conversion bug caught by a two-line test at a desk costs nothing, while the same bug found on a moving robot can break hardware.