Member-only story
5 Essential Tips to Debug Any Piece of Code
Level up your debugging skills
Yes, here I go again with the bugs. Bugs are still one of the most frustrating things to encounter when you are coding. I know I find them frustrating to some extent. All you coders out there will agree that there is nothing quite like building something that you think will work only to have it break in front of your face.
But, do not get me wrong: bugs are not entirely terrible. You can always learn a thing or two when trying to debug any program. Some of the most rewarding experiences I have had involve fixing a nasty bug. That feeling you get when you watch it melt away at your fingertips is priceless. There is a famous phrase that goes like this:
“If debugging is the process of removing software bugs, then programming must be the process of putting them in. — Edsger W. Dijkstra”
It is pretty snarky, but I agree with the fact that most programs are not without bugs.
It is tough to know every scenario and state that your code will be running when you are writing it. Because of this, bugs are a natural side effect of coding. Unfortunately, that does not make it any less frustrating to deal with said bugs, especially if they are responsible for completely breaking your program.
With that said, there are skills and methods in debugging that help make the process go a little smoother. In this piece, I will share five of my tips on how to debug easily. Most of these tips come from David J. Agans’ textbook “Debugging: The 9 Indispensable Rules for Finding Even the Most Elusive Software and Hardware Problems.” Some of them are from my experience dealing with bugs. Let’s get into it.
1. Reproduce the Behavior Consistently
Reliably reproducing bugs is half the battle. You have a much better chance of identifying and fixing a bug if you can reproduce it the same way every time. When you identify a bug, do not even think about the code that might be having the issue. Just think of the code as a black box and figure out what inputs may have caused the bug. Once you can reproduce it, shorten the steps it takes to…