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:
- Gather the data.
- Develop a hypothesis.
- Test the hypothesis.
- Repeat until the test succeeds.
- 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.
To really fix a bug, you have to reproduce it first. Fixing a bug that you can't repeat is just performing guesswork...