The Four Steps of Debugging

This article is about the concept on how to debug a program; No matter which language and platform you are using or no matter you are making front end or backend, the following concept will help;


Identify is the first step in the debugging, it means discover what is the bug and why it happen

We need to identify the way to reproduce the problem and the root cause of the problem; If we cannot sort out, sorry that we probably cannot solve the problem;

Here are some techniques help us identify the problems:

Asking the users or testers:
Our users or testers can tell us which platform found the problem, or even tell us how to reproduce the problem;

Screen Capture can help you know what exactly happened apparently;

Logging and Debugger:
Sometimes the screen cannot tell us many information or there are no screen if we are developing backend programs. Therefore, Logging or Debugger is a way to tell us what’s happening inside the program while it is running.

In many situations, you cannot reproduce in the production environment or you are not allow to do so; However you can do it in your sandbox (e.g your development server) because you can highly control your own environment such as limiting the memory, creating busy traffics, …


Isolate is a step to separate the buggy code with other healthy code; I usually make an Unit Test referencing that part of code and then reproduce the bug using that unit test;

Isolation has the following advantages:

  • Won’t affect other code
  • Save time to repeat the testing steps
  • Easy to examine difference cases using the buggy code;

If you found that it is hard to make an unit test for the code, try to refactor your code first base on SRP (Single Responsibility Principle) first;

This step is usually ignored by developers; We could skip this but it is likely to cause bad things happened such as poor effectively or making more bugs;


Fix is a step to correct the buggy code; This step is the core part of debugging; If the above two steps are doing well, it should be easy to handle this step;

Here are some tips about fixing codes:

  • Understand your code & Understand the libraries you are using;
  • Read the Document of those functions you are using;
  • Seek answers from
  • Code Walkthrough
  • Make unit tests to test the suspicious statement
  • Open Debug Mode
  • Work with debugger
  • Try to refactoring or re-design the architecture (worst case scenario)


Review is the final step and is easily forgotten by us; Review is a step to ensure the bug you fixed are working correctly now. Also the changes are not affecting other parts of the application and working properly in the target platform;

Here is my case that not doing review after I fixed a bug: I fixed a bug on my iOS program, it passed the unit tests, it is working on my development environment;

However, It crashed on the different iOS version; My fixed is using a function that supported by the latest iOS SDK but not the old one; Thus, a crash was shown up when running in an older version of iOS;


Debugging is the inevitable work in programming and I could say it is the most annoying work in programming because it is time consuming and will not create any extra values;

Your boss and your clients do not want to spend time and money to let you keep debugging;

So it is important to improve our skill to debug efficiently;

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s