Home  >  Article  >  Backend Development  >  12 Key Steps to Fixing Bugs

12 Key Steps to Fixing Bugs

伊谢尔伦
伊谢尔伦Original
2016-11-26 09:31:02988browse

boss: So, how long will it take you to fix this bug?

Inexperienced programmer: Give me an hour? Two hours at most? I can get it done right away!

Experienced Programmer: Let’s put it this way, it takes me as long as it takes to catch a fish? !

How long it will take to fix the bug is difficult to know in advance, especially if you are unfamiliar with the code, the situation will be even more confusing. In the book "The Art of Agile", James Shore clearly points out that if you want to fix a problem, you must first know what the problem is. The reason why we can't accurately estimate the time is because we don't know how long it will take to find the crux. Only by knowing this, can we reasonably estimate the time it will take to fix the bug. However, I am afraid that the day lilies are already cold at this time. Steve McConnell once said:

"Find the problem - understand the problem - this is 90% of the programmer's job."

Many bugs only need to change a certain line of code. But what requires a lot of time is that we have to figure out what is correct later - just like when we are fishing, we have to know where to put the bait, when the fish is easy to take the bait, etc. It is said that there are four types of bugs: the first type is easy to find and easy to fix, the second type is hard to find and easy to fix, the third type is easy to find and hard to fix, and the fourth type is hard to find and hard to fix. The most tragic thing is the last type. Not only is it "searching and searching, but it is desolate and desolate", even if it finally breaks through the stone after all the hard work, one can only scratch one's head and scratch one's head involuntarily, sighing helplessly: "The road is long and long." ". It can be said that unless it is freshly released code, looking for bugs is like a blind man feeling for an elephant - you are confused and don't know which bug type it belongs to.

12 Key Steps to Fixing Bugs

Finding and fixing bugs

Do you know what “finding and fixing bugs” means? That’s right, it’s debugging! Constant debugging, countless debugging! Through extensive work, Paul Butcher summarized the following structured steps:

 1. Clarify the purpose. Carefully review the exception report to determine whether it is a bug, find various useful information, discover the crux of the problem, and reproduce it. Check again for duplication with the report. If duplication occurs, see how the people involved dealt with it.

 2. Preparation - Find the correct code and clean up the work area with elimination.

 3. Match the test environment. This process can be skipped if the customer is working on computer configuration.

 4. Clarify the purpose of the code and ensure that everything is working properly with existing testing tools.

 5. Okay, now you can go fishing - reproduce and diagnose the error. If you can't reproduce it, you can't prove you've done the repair work.

 6. Write test cases, or catch bugs through ready-made test cases.

 7. Enter repair mode - make sure it does not affect any other parts. However, before you start fixing it, you may want to do the refactoring because only then you can mess with the code without fear. And post-regression testing can also ensure that you will not add any new bugs.

 8. Organize the code. Make your code easier to understand and safer through step-by-step refactoring.

 9. Find someone else to review it, the authorities will be confused and the onlookers will understand.

 10. Check this repair process again.

 11. Try not starting from the main line to check whether these bugs will affect other branches. Merge these changes, handle differences in the code, review all reviews and tests, etc.

 12. Think. Think carefully about what went wrong and why? Why does your fix work? Where else would this type of bug appear? In the book "The Pragmatic Programmer", Andy Hunt and Dave Thomas also pointed out that "if a bug costs you a lot of time, then you must find out why." In addition, we also need to think about how to learn from experience and lessons so that we will no longer stumble on similar issues in the future. And, is there anything that can be improved in the methods and tools we use? and the impact and severity of these bugs.

Which one takes more time, finding the bug or fixing it?

Perhaps the time required to set up a test environment, reproduce the problem and test the bug is far more than the time to find the bug and fix the bug. But for a small number of obvious bugs, finding them is easy—but fixing them may be less than ideal.

In the book "Making Software", there is a chapter that mainly discusses "the source of most software vulnerabilities". Dewayne Perry analyzed that compared to repairing, the time required to discover bugs (including understanding bugs and reproducing bugs) longer. Studies have shown that most bugs (almost 3/4) are both easy to find and easy to fix: 5 days or less (this is based on large-scale real-time systems through heavy-duty SDLC, extensive review and testing). But there are also very disgusting bugs. Even if you can catch it easily, you still have to work hard to fix it.

Discover/Repair Repair time5 days

Can reproduce the problem 72.5% 18.4%

Difficult or impossible to reproduce 5.9% 3.2%

So if you bet You fix bugs quickly, and most of the time you're right. But when you lose the bet, then, hey, it means you're in big trouble.

So, next time, when the boss asks when the bug will be fixed, don’t answer stupidly “it will be done soon”.


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn