Bugs are inevitable part of writing code and are part of our lives 😄, we deal with them every single time.
The process of tracking down the cause of the error or bug is what we call debugging.
We have always have the option to either paste our error in the Google search box or if we have some googling skills, we can figure out a way to ask Google and get the best result.
But, sometimes it not that you didn't use the framework correctly or you messed up with the module. It an internal bug, meaning your code itself is the problem.
There can be two face to a bug, your program could be:
throwing an error
or, it not providing the desired result.
If the program is throwing errors, then it easier to fix or easier to Google search.
The real issue is when it not providing the desired result.
In this article we will be looking at steps that are guaranteed to help you in figuring out why, where and how to fix bugs in your code.
1. Printing
What printing means is that you are outputing something at a point where you think the error is happening.
These varies alot based on the programming language and the program, each language has a way to output to the console.
This is the simplest form of debugging and can help alot with debugging your code.
2. Debugger
The debugger is a tool that will allow you to execute your code line by line at your own pace.
Debuggers are built into the most popular ides, text editors and browsers. It works with multiple languages including compiled languages and also in browser.
The ways it works is, you set what is called a breakpoint; which is a line in your code which the execution will be paused. Then you can take over by executing subsequent lines manually.
This allow you to see the changes in your program line by line, and easily help you to figure where or what the issue might be.
3. Rubber duck
Rubber duck debugging simply means explaining your code to an object, your pet or even another human or developer.
Rubber duck is like an umbrella term, which is the object most developers have on their desk they explain their problems or errors to.
The duck or the object will not give you the answer or solve your problem. But in the process of saying your problem out loud 🔊 , a solution might start to ring in head.
Conclusion
The bug you might be having may be a kind that never existed or a problem you cannot craft a question to feed into the Google search box.
These techniques will definitely help you to conquer most of your errors or bugs.
Top comments (2)
nice! how is it that 2 years into coding i have only tried printing when trying to fix a bug?
😅, maybe it because most bug you have been facing can easily be fixed when you see what going on.
But, it really doesn't matter the method you used, so far as it solves the problem.