Wednesday, 15 April 2020

2 Effective ways to debug your code | Code Revisited


We all have experienced the situation, where our program behaves different to what we actually want from it. In most cases, it is the simple bugs that we have missed during the development. And yet, it gets untraceable. Rather than staring at the program, thinking of what exactly went wrong, what you can simply do is debug it.


Here are 2 effective ways to debug your program.

Visualize the Flow

In order to apply this method in your development life cycle, you should be in a state to know what exactly you want the program to perform.

With this in place, it not only helps you understand the core logic, but also helps you to quickly catch up the exact bug that is restricting your program to perform the task you want.

Once you have a clear picture of your requirement, you convert that into the code that will do the task for you. This makes it easier for you to visualize the code, and look for possible points where you might have gone wrong.

Often times, it is actually problem with the object set. Of which NullReferenceException is the most – for me. So, remember visualizing your code, to figure out the most-likely points where you are setting up an object, or setting up data into an object.

Debugger

Possibly the most time consuming method when it comes to finding the error in the program. In case you are not familiar with the code, but you are assigned to trace out the issue it is causing to the system, then you can simply use the debugger.

Because, everything is in there, the code holds everything you are looking for, and it is just that you need to create or trace ways to find it.

Get the breakpoints in place, and run the program. As you get going with the breakpoints, subsequently hover over the objects to see what it holds currently.

This method proves to be efficient, but it consumes a lot of time, and is recommended to those who are not familiar with that piece of code.

But you have many more ways to debug a code, of which I believe these two are the most effective. If you would like to add your favorite way of finding the issues, or suggest to add other ways to this, please share with us in the comments.

No comments:

Post a Comment