search
HomeBackend DevelopmentPHP Tutorial12 Key Steps to Fixing Bugs
12 Key Steps to Fixing BugsNov 26, 2016 am 09:31 AM
bugphp

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
php怎么把负数转为正整数php怎么把负数转为正整数Apr 19, 2022 pm 08:59 PM

php把负数转为正整数的方法:1、使用abs()函数将负数转为正数,使用intval()函数对正数取整,转为正整数,语法“intval(abs($number))”;2、利用“~”位运算符将负数取反加一,语法“~$number + 1”。

php怎么实现几秒后执行一个函数php怎么实现几秒后执行一个函数Apr 24, 2022 pm 01:12 PM

实现方法:1、使用“sleep(延迟秒数)”语句,可延迟执行函数若干秒;2、使用“time_nanosleep(延迟秒数,延迟纳秒数)”语句,可延迟执行函数若干秒和纳秒;3、使用“time_sleep_until(time()+7)”语句。

php字符串有没有下标php字符串有没有下标Apr 24, 2022 am 11:49 AM

php字符串有下标。在PHP中,下标不仅可以应用于数组和对象,还可应用于字符串,利用字符串的下标和中括号“[]”可以访问指定索引位置的字符,并对该字符进行读写,语法“字符串名[下标值]”;字符串的下标值(索引值)只能是整数类型,起始值为0。

php怎么除以100保留两位小数php怎么除以100保留两位小数Apr 22, 2022 pm 06:23 PM

php除以100保留两位小数的方法:1、利用“/”运算符进行除法运算,语法“数值 / 100”;2、使用“number_format(除法结果, 2)”或“sprintf("%.2f",除法结果)”语句进行四舍五入的处理值,并保留两位小数。

php怎么根据年月日判断是一年的第几天php怎么根据年月日判断是一年的第几天Apr 22, 2022 pm 05:02 PM

判断方法:1、使用“strtotime("年-月-日")”语句将给定的年月日转换为时间戳格式;2、用“date("z",时间戳)+1”语句计算指定时间戳是一年的第几天。date()返回的天数是从0开始计算的,因此真实天数需要在此基础上加1。

php怎么读取字符串后几个字符php怎么读取字符串后几个字符Apr 22, 2022 pm 08:31 PM

在php中,可以使用substr()函数来读取字符串后几个字符,只需要将该函数的第二个参数设置为负值,第三个参数省略即可;语法为“substr(字符串,-n)”,表示读取从字符串结尾处向前数第n个字符开始,直到字符串结尾的全部字符。

php怎么替换nbsp空格符php怎么替换nbsp空格符Apr 24, 2022 pm 02:55 PM

方法:1、用“str_replace(" ","其他字符",$str)”语句,可将nbsp符替换为其他字符;2、用“preg_replace("/(\s|\&nbsp\;||\xc2\xa0)/","其他字符",$str)”语句。

php怎么查找字符串是第几位php怎么查找字符串是第几位Apr 22, 2022 pm 06:48 PM

查找方法:1、用strpos(),语法“strpos("字符串值","查找子串")+1”;2、用stripos(),语法“strpos("字符串值","查找子串")+1”。因为字符串是从0开始计数的,因此两个函数获取的位置需要进行加1处理。

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools