Tips for resolving a bug

In a perfect world there would be little need for debugging. Unit tests would be in place for all existing code and whenever a spot was missed a test would simply be added to cover the whole. In the real world or at least the world that I work in there is much legacy code. There also other things that affect system functionality such as system complexity - our app is close to two million lines of code, familiarity with the system, developer experience.

These things require the developers to follow a structure format when resolving new bugs. Here are some tips that I came up with and passed down to my team.

The steps don’t have to be done in the exact order but they should be done prior to sending the ticket up for code review.

1. Duplicate the error
If you can’t duplicate the error don’t move beyond this step. At this point do whatever you have to do see the error for yourself in your box. Do not even think about fixing code that will work in theory. I have been bitten by this many times.
2. Study the problem and the functional area
Make sure you understand at a high level the problem that you are solving and peripheral areas. Do you really understand what the codes BC1 and BC0 mean and why the code can’t go from BC1 to CC2 (hypothetical codes)? Understanding what you are doing will help you solve the problem much easier.
3. Debug and find the problem
Run the problem and find out where it takes the wrong turn. There is an opportunity here to discover the intent of the code. Code is always good at telling you what it’s doing but not why. Can it be written better to be more understandable? If it can keep that in mind when you refactor it and also when your write new code.
4. List your assumptions and unknowns and discuss them with the business analyst or customer if you have one.
You are allowed to assume anything and everything you want about a system except that your assumptions are correct. Have your assumptions verified by someone who knows more about that area than you do. This could be a BA or a more senior developer.
5. If you can’t reproduce the problem, have the person that created the ticket reproduce the problem in their box. Many times this will reveal incorrect assumptions about how you thought the bug was supposed to be re-produced. At other times it will provide an opportunity to explore the difference between your environment and the environment where the bug was discovered.
6. Explain the problem and how you plan to solve it to someone else.
Normally we are all under pressure to get things done quickly. For that reason everyone is always busy with something. However what’s good for the team is good for the individual. Slow down and present the problem to another developer and have them see it. Explain it to a BA. Many times the BAs will understand enough or pick up on enough of your programming lingo to provide clues about the right solution.
7. Solve the problem in code.
Once you solve the problem test it out in the other scenarios that apply not just the scenario that the bug was found.


Three key things that we must keep in mind throughout the process are:

1. Document your research - in our company we should do this in our Bug Tracking system; Trac
2. Open communications with the entire team (BAs, Testers, Developers)
3. Slow down - to provide the correct solution. The right solution seems slower at first but it’s actually faster when you consider re-work.

Comments

Nolan Egly said…
6.5) Write a failing unit test that proves the defect exists
8) Ensure unit test now passes, proving the defect has been fixed.
9) Ask yourself, "Where else might this error have occurred?" Try to use an automated method to detect other potential occurrences.

Popular posts from this blog

Simple Example of Using Pipes with C#

Putting Files on the Rackspace File Cloud

Why I Hate Regular Expressions