Quick tips to debug efficiently

Debugging is the process of finding and resolving defects or problems within a computer program that prevent correct operation of computer software or a system. It can often become frustrating and from personal experiences I could spend an hour trying some quick fixes as opposed to methodically debugging the issue instead. This process leads to wasting time and also getting very frustrated. So today I thought I would do a quick blog on some helpful tricks with debugging.
Print Things!
An obvious one but perhaps the most important. Print things!! Print out your variable names, print out the name of the method you are in, print out the changes to variables. This will enable you to understand the flow of your code and at which points variables are changing.
Run your code!
A really sensible process to perhaps even prevent the bug is run your code after every change in your code. Now I wish I could preach about this but we are all guilty of trying to complete our task by writing lots of code without testing it works. However having said that hours could be saved if you consistently check that each line of code works.
Eliminate possibilities through commenting
Process of elimination is a good method of eliminating the possible causes of a bug. For example commenting out sections of code to see whereabouts the bug is originating from. This can help you narrow down the possible options.
Step away!
However when all else fails sometimes the best thing to do is step away from the keyboard. Take a break, clear your head and come back at a later stage. I know this has worked for me before, especially when my head feels fried and there is no solving this bug. Coming back later can help give a fresh perspective. It certainly has helped me in the past
Ask for help!
Another difficult issue I have found is trying to debug someone else’s code. Code that you don’t understand or have had no previous experience in using can be difficult. In this case sometimes the best thing to do is ask for help. Simply write out what your problem is and articulate your issue to a member of your team.
To conclude debugging isn’t easy but it’s an essential skill if you are to get anywhere in software development. Some even say that 75% of a developer’s time is spent on debugging. So take some time to hone your skills in debugging to allow yourself to become a better programmer. Think of it like a puzzle or a crime you want to solve.

Comments