Methods for bug-free code
We will briefly look at some methods that will help us to minimize the number of bugs that could be introduced into our code. These methods will also aid in giving us confidence as to the portions of the code that introduced the bug:
Figure 11.1: Different methods to debug code
Let’s look at these methods in more detail.
Coding incrementally and testing often
Let’s consider the approach of developing incrementally. This means developing the program incrementally and testing it often after adding an incremental piece of code. This pattern will help you to track bugs easily because you are testing every small snippet of code as opposed to one large program.
Writing unit tests
When a test is written and code changes occur, the unit test protects the code from potential bugs being introduced. A typical unit test takes a given input and validates that a given result is produced. If the unit test is passing...