It is time for honesty. There is a dirty little secret we need to discuss. It might be surprising even. However, we need to talk about the bugs in our code. We all would like to think about writing error-free code. Unfortunately, we also all know that we code bugs more than we want to admit. Therefore, we spend a substantial amount of our time debugging errors ranging from typos to logical flaws. That leads to the topic of this episode. Here are three ways to approach your mistakes that will lead to faster debugging.
Verify The Source is Correct
The most common source of errors is not logic or even typos. It is an out-of-date piece of source code. This stale code may either be due to a failed save or cached source that needs to be cleared. Think about it. How often do you hear about or encounter a bug on a web page and your first response is to clear the cache? This issue extends out to properly saving and deploying files. It is incredible how often a simple fix like saving, deploying, or clearing a cache fixes the problem. That all points to the most famous approach to fixing broken software; turn it off and then back on again.
Isolate The Problem For Faster Debugging
The idea of fixing a problem where it occurs seems obvious. However, the complexity of modern software can make that a challenge. We often deal with several layers of logic and nested calls. This architecture can make it easy to miss the step that creates the error. That means we need to be intentional in tracking down the code that is broken. When we do not, we run the risk of applying duct tape to a symptom instead of correcting the core error.
When I look back on the most common mistakes I have made in debugging; assumptions are the bane of my existence. Whether it is an assumption that my code works or that third party sources are correct, the result is the same. We can spend hours chasing down phantom issues when assumptions point us in the wrong direction. This recommendation is similar to isolating the problem. However, assumptions can often lead us away from identifying the real issue. Do not be afraid to peel all of the layers of your logical onion in an attempt to chase down that bug.