Debugging

Fixing bugs in a complex program can be a complicated task. Sometimes, bugs are straighforward, while others are hard to reproduce or fall into the "there's no way that the current code produces this result" area.

A good programmer doesn't use random changes to the code to fix problems but approaches debugging methodically. Different people use different debugging approaches, but they can be typically summarized in the following steps:

  1. Gather the data.
  2. Develop a hypothesis.
  3. Test the hypothesis.
  4. Repeat until the test succeeds.
  5. Add a test to the unit tests.

The last step (regression testing) is especially important as it prevents the bug to be accidentally reentered into the code by merging the incorrect version of the source.

Get Hands-On Design Patterns with Delphi now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.