You know the 5 normal forms and the corresponding rules of data normalization. You know the 7 Layers of the OSI model and the 23 most important design patterns. But how do you produce a bug free program? Testing is the key. If the carpenters’ rule is “measure twice, cut once”, then the programmers’ rule is maybe “code once, test twice“. Manual testing is an indispensable part of the development process. It allows the discovery of bugs in the first place and closes the agile analysis-design-code-test loop. Self-testing programs are even better: if you have enough tests, the program can discover itself if there is something wrong. But in order to cover your application with tests, you still have to debug large parts of it. There is no such thing as a bug free application, you have to build it until it works, then test it until it hurts.
The two fundamental laws of bug finding are:
- a bug that can not be reproduced can not be solved: from the outside perspective of the user, you need to know the situation when and where exactly a bug occurs. If you can not reproduce a bug, the programmers can not test if their solutions work. To fix a bug you must perform three essential steps: reproduce it, solve it, test it. It is neceassary to prepare an experiment which isolates and reproduces the bug. This experiment is the only way to determine if the bug is eliminated or not.
- a bug that can not be tracked can not be solved: from the inside perspective of the programmer, you need to what the program is doing when a bug occurs. If you don’t know what the code does, you will hardly track a bug. To identify a bug, you must try to find out what the code really does: look at the code directly with the debugger or indirectly through the logs. If you don’t look at the code, you can only make educated guesses. Therefore logging is the first step to track a bug.
To sum it up, if you want to get rid of bugs, you need to spot them, track them, and hunt them down. Somehow humans have done this for the last 100.000 years. They read tracks and trails instead of log-files, and they used spears and arrows instead of IDEs, but basically it is similar. One common hunting technique is isolating the prey from the herd (which is equivalent to reproducing the bug).