How to fix bugs effectively? – Heading

Tram Ho


Today, after a few weeks of research, I searched the bookshelf to find ways to fix bugs most effectively. I decided to write this series. Hope it will be helpful for you in fixing the bug. In this article, I decided to apply Buddhist thought as a foundation from theory to practice in dealing with difficult bugs to make programming work smoothly.

There are a lot of suffering and deadlock in human life, dev work is similar, and the most painful is probably always having bugs and spending hours, even weeks, and months to fix the problems. bug that sometimes fixes one bug after another comes out. According to many statistics, the dev’s job is only about 20% to develop new features, the remaining 80% is for fixing bugs. Therefore, the task of programming thought to be lighthearted because being able to enjoy the passion was turned out to be extremely headache. Because of a bug that sometimes leads to insomnia. Family happiness is sometimes dull because only in the days when the bug is difficult, your wife does not understand why today he seems so cold and scowling with me like that.

Four Noble Truths

What is an effective bug fix? Is a bug fix fast? Not. Is to fix in place, fix the root of the bug, fix so that no new bug will be generated, fix so that in all cases our program still works properly as required.

On the basis of the Theravada Buddhist ideology, instead of praying for a supernatural being like the Bodhisattva Guan Yin to save suffering from our bugs, we should apply the foot path. the reason Buddha Shakyamuni pointed out in the Zhuan Falun about his experience in enlightenment. The path of truth is the Four Noble Truths that I am about to present below to you. The teachings of the Four Noble Truths are the most important core recognized by all sects as the most common and purely common point of Buddhism. Understanding these doctrinal points can be seen as having penetrated the entire path of enlightenment and liberation of the Buddha.

In the Zhuan Falun, the Four Noble Truths are recorded as follows:

  • Bhikkhus, this is the Noble Truth of Suffering: birth is suffering, sickness is suffering, old age is suffering, death is suffering, hatred meeting each other is suffering; friendly li is suffering, demand is not suffering, in summary aggregates grasping is suffering.
  • Hey monks, this is the Noble Truth of Suffering. It is love that leads to being, corresponding to piti and greed, seeking pleasure and happiness here and there, it is craving, birth, and nothing else.
  • Hey monks, this is the Noble Truth of Kill. It is the cessation of sexual immorality, abandonment, renunciation, renunciation, liberation and liberation.
  • Bhikkhus, this is the Way to end the suffering of the Noble Truth, which leads to the cessation of Suffering, it is the path of eight things that help us witness the Way: Right Understanding, Righteous thoughts, Right Speech, Righteous karma, Righteousness, Righteousness Advancing, Mindfulness, Concentration.

We can summarize as follows:

  • The Noble Truth of Suffering is the truth about suffering (explaining what suffering is).
  • The collection of the Noble Truths is the truth about the arising of suffering (explains why suffering is)
  • Kill the Noble Truth is the truth about the cessation of suffering (explain what it is to eliminate suffering)
  • The path to destroying the Noble Truth is the truth about the way to eliminate suffering (explain how to eliminate suffering)

That is the Four Noble Truths for human life, and for bug fixation work, if one considers bug synonymous with suffering, then fixing bug bug means eliminating suffering. So, if we apply the Four Noble Truths to bug fixing, we will need to understand: what is a bug, why a bug is, how to fix a bug, and how to eliminate bugs.

Holy suffering in fix bugs

You have to understand what the bug is, how it happens, in which case it is known that the fix is ​​correct. It is like going to the doctor to know the symptoms of the disease, knowing where the disease is, having to test and diagnose the disease correctly. Strictly speaking, you have to reproduce a bug before you start fixing any code.

You can immediately make some assumptions, rush in to fix, check the code that runs properly, package and sit there thinking that you have successfully fix. Like some of my friends who know how to fix it, I don’t understand why my code works. That is a typical mistake. The next day, the tester reported that the bug had not been fixed. And you repeat making assumptions, plugging in the fix again a few more times.

You NEED to reproduce the most accurate scenario where an error occurs. It should be the script with the fewest steps to get the scope of the fix narrowed down. If you can’t replicate yourself, ask others. Nothing is more stupid than groping in the dark.

How to reproduce the bug perhaps I’ll share more in the next article.

Practice the holy format in the bug fix

You have to understand where the bug comes from, what file, class or method causes it to know where to fix the code. Just like when seeking medical attention, it is important to know where the disease is coming from so that you can find the most appropriate and effective treatment.

Some bugs will allow you to detect the cause through the IDE’s stacktrace. Take advantage of this to know exactly where the bug was created. The ability to read and understand stacktrace quickly is an essential skill in your dev career. The key is that you need to find the root cause, and it is usually located at the bottom of the stack. My experience is that by reading the stacktrace from the bottom up, it’s faster to find the cause.

Some people have the habit of copying the entire stacktrace to search Google in hopes that more people will encounter this bug just like me. Maybe they were lucky enough to find a topic on StackOverflow and press Ctrl + C, Ctrl + V and see the code run smoothly. This will cause you to not understand where the root of the bug is, so it will not help you understand and learn anything. Also, it is unlikely that the code will fix your bug because sometimes different bugs may produce slightly similar stacktraces.

In short, you need to understand the cause of the bug, or you are just a charlatan who does not know how to be a good doctor.

In addition to using stacktrace, there are a few more tips to investigate the cause of bugs that I will definitely share in subsequent articles.

Kill the holy empire in the bug fix

Once you know where the bug comes from, fixing the bug is probably much simpler. Just like when you come to the hospital and have known the exact cause of the disease, we will give you a treatment plan that is suitable for each different disease.

Just like a good doctor will come up with the most effective, low-cost, least-effective treatment regimen, whether the bug fix will work or not depends on the experience and level of the fixer.

If you have had enough experience and knowledge to handle the bug with minimal line changes and the narrowest impact range, then be confident to fix it. If you do not have much experience and expertise, ask the better ones. Take advantage of sources on the internet like Google, with providing as much information as possible in the search bar, chances are you’ll find the most effective fix. Choose the most concise suggestions that are easy to understand, have the highest upvote and the latest updates, note that you must understand the suggestions before pressing Ctrl + C. If you find it difficult to understand, give priority to try to find Other suggestions are easier to understand. That will help you master and apply it to your code.

Another way is thanks to the more experienced people in the team. Sometimes they can suggest solutions that you didn’t expect to be so easy to understand and concise. Note again that asking people in the team should only be applied when you are sure of the cause of the bug. If you do not know where the bug is and have asked someone else, they will be forced to sit around looking at the code and find the cause with you. It takes their time because you understand the code and your project but have not found it yet, an outsider cannot find it quickly.

Dao destroys the Noble Truth in bug fix

The bug fix path is a very long way and every program you write will have lots of potential bugs coming soon. The path to getting rid of disease is also a long-term path, and you need to be persistent in taking medicine to cure the disease at the root and maintain a scientific lifestyle to prevent it.

The way to avoid headaches with bug fixes is to apply clean architecture, clean code, minimize complex logic, write understandable code and master them. In addition, it is also necessary to cultivate knowledge and experience so that if a bug occurs, they will confidently fix them. Instead of evading a bug fix by blaming the platform or someone who goes before a bad code and refusing to fix a bug, ask for more time to learn. Refactoring the code smells is also a way to make it easier to fix bugs in the future.

Whenever fixing a difficult bug, please enjoy that feeling and relax a bit. Because you have just taken a new step on the journey to become a good physician. You can record them in a notebook so that if you meet again later, it doesn’t take much longer.

Gradually when you have enough experience you will find that fixing the bug is quite an interesting job, each bug is difficult like a new boss in the game that you will need to destroy with a sharp experience sword in hand.

And if you can write perfect code without generating bugs, it’s even better. Support must kill to create karma.


In the following articles in this series I will include more examples to show the methods and tips that I have gathered from friends and on the internet. We hope you support and contribute more. I include a little bit of Buddhist philosophy and I hope that anyone who is curious can learn about Theravada Buddhism so that they can have a more meaningful and happy life.

Share the news now

Source : Viblo