How to fix a bug

You get a bug report for your project; now what? There is an amateur way to fix a bug, and there is a professional way to fix a bug.

The amateur fixes the bug, restarts the software and checks that that specific bug doesn’t occur anymore. If the bugfix introduced or exposed other bugs, the amateur may or may not find them, but if he does, he goes back to square one and starts fixing the other bugs. We can call this approach “fumbling and thrashing about”.

The professional programmer first runs the test suite — he has a pretty comprehensive test suite, of course — to make sure all tests currently pass. He then writes a test that exposes the bug and runs the test suite again to check that this, and only this, test fails. Then he fixes the bug and runs the test suite again. Now all tests should succeed, which means both that the bug has been fixed and that no regressions have been introduced.

It is a clean approach that aims for consistency, repeatability and clarity.

The distinction between a professional programmer and an amateur programmer is not just about being paid for one’s work. It is a mindset and a way of approaching one’s craft.

Pin It on Pinterest