Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Three questions to help you, debug.

2025-02-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/03 Report--

Translator's note: Debug also wants to save my body three times!

Original: Three Questions About Each Bug You Find

Translator: Fundebug

In order to ensure readability, this paper adopts free translation rather than literal translation. In addition, the copyright of this article belongs to the original author, and the translation is for learning only.

Do you find that sometimes, when a BUG is repaired by us, you find another BUG caused by that BUG, or introduce a new BUG due to defects in the repair algorithm? So every time I fix BUG, I ask myself three questions to make sure I think it through. You can also use the same method to improve the quality of your code.

The core idea of these well-designed questions is that every BUG is the appearance of a hidden core problem. You need to solve these superficial symptoms, but if you only cure the symptoms, you will eventually relapse elsewhere, not the root cause; you need to find the core problem that causes this BUG and correct it. The core problems that lead to BUG are generally not random and uncontrollable, as long as you understand why it occurs and what causes it.

Before you ask yourself these three questions, you need to overcome your inertia and carefully analyze the causes of BUG. By starting with the location of the code where the BUG appears, ask yourself step by step why it went wrong, and look back at the program execution steps backwards until you find the pattern in which the BUG appears. Often Debug with colleagues will help you confirm your hypothesis.

The program exception is because the subscript variable J is out of bounds.

Why?

The length of the array is 10 and the maximum subscript is 9, but the subscript J is already 10.

Why?

J is the length of the entire array, but the indexable subscript is 9.

In the process of looking for the cause of BUG, also check the values of key variables to see if you can explain why the values of variables are so in this case.

Why is name null?

Why is an error message printed?

You need to know exactly what happened to the program, that is, to record all this information for easy analysis.

Now let's look at these three issues.

1. Has this mistake been made anywhere else?

See if similar programming methods have been used elsewhere in the code, and appropriate divergent thinking can also help you find similar BUG.

Is the length of the array used as the subscript elsewhere? Are all arrays derived from the same original array? Will there be a problem if the length of the array is 0?

Try to describe the logic that this code should follow, and code with BUG violates that logic.

The initial value of the start point of the array plus the length of the array and minus 1 is the subscript of the last array element. If the length of the array is 0, it is not satisfied.

If you modify one BUG at a time and fix several other potential BUG at the same time, it will greatly improve your productivity. Trying to describe the problem in a more abstract way will help you understand the entire program to prevent the introduction of new BUG.

two。 Is it possible to hide another BUG behind this BUG?

When you have figured out how to fix the BUG, you can anticipate the behavior of the program after the BUG repair. The statement after the line of BUG code may also hide BUG, but the program did not perform this step before because the BUG crashed, or because the fix may return other values that were not previously considered. Try asking yourself the following questions:

Can the next statement be executed successfully?

When you look at the control flow of the program, you can figure out what code has not been executed.

Have I tested the combination of these attributes?

Checking the possible combinations of attributes doesn't take much effort, and you'll often find that there are a lot of situations that developers don't take into account!

Can I test all the error messages?

Be aware that changes in one place may lead to BUG elsewhere. Local changes to a variable may violate some of the previous assumptions.

If I just subtract J from 1, and if the length of the array is 0, the next line of code will try to manipulate the element in the array at-1.

If you have made a lot of changes to the program, consider carefully each time whether it is the right thing to do, or even need to redesign and implement this part of the code.

3. What should I do to avoid similar BUG?

You need to try to find ways to solve the problem at its root. Using new methods and tools can often eliminate all BUG of this type directly, rather than discovering and solving them one by one.

To find out when BUG was introduced, can it be avoided during the development phase?

There is nothing wrong with the design; I introduced BUG when I wrote the code

Carefully examine the cause of BUG, sort out the code logic in which BUG occurs, and see how to correct it.

Defining new and different types to block the index and length of the score group can find this error at compile time. (the index type can limit the maximum length of the index)

When each array element is output, the corresponding subscript calculation method is output, so I can find the problem quickly.

Suppose your reason for generating a BUG is "too many variables, I just forgot", then what you need to do is to improve to make sure you don't have to remember many variables.

About Fundebug

Fundebug specializes in real-time BUG monitoring of JavaScript, WeChat Mini Programs, Wechat, Mini Game, Mini Program, React Native, Node.js and Java. Since the official launch of Singles' Day in 2016, Fundebug has handled a total of 700 million + errors, which has been recognized by many well-known users, such as Google, 360,360, Kingsoft, people's Network and so on. Welcome to try it for free!

Copyright notice

Please indicate the author's Fundebug and the address of this article when reprinting:

Https://blog.fundebug.com/2017/08/23/three-questions-about-each-bug-you-find/

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report