How to Debug Code (Without Crying)
Void⚡
Posted on December 15, 2022
Debugging code is an essential developer skill.
Use these 5 effective techniques to level up your debugging game.
Let’s go! 🚀
TL;DR
- Narrow down bug scope 🎯
- Use debugging tools ⚒️
- Write test for the bug 🧪
- Use rubber duck strategy 🦆
- Take a walk 🚶
Narrow down bug scope 🎯
First, identify cases for which the issue occurs.
Then, you can analyze corresponding defective code.
Navigating whole code base for fixing a bug is:
- ineffective
- tiring
- time consuming
Localize the bug before fixing it.
Use debugging tools ⚒️
Spend some time learning about:
- Debugger
- Chrome Devtools
- API verification tools
- Analyzing heap dumps
- Packet sniffing tools
You don’t need to learn all of them.
Only the ones that are useful for your stack.
Find what works. Use them often.
Write test for the bug 🧪
Every bug is a failing test case.
Use tests to:
- reproduce the issue
- verify the fix
Remember:
Test >> Bug documentation
They prevent future appearance of the bug.
Use rubber duck strategy 🦆
It’s a fancy term for “Thinking out loud”.
Idea is to explain your code line by line to a rubber duck.
It forces you to come out of the perspective that introduced bugs in the first place.
Also, the tip works with pets too :)
Take a walk 🚶
While debugging you will get stuck.
A lot!
So limit the time spent in a session.
After that, take a break.
Let your mind wander.
Clear your head and come back later.
This tip works best for me.
Wrapping up 📝
That’s it.
Hope these tips will help you in debugging your code.
Share in comments your best debugging tip.
If you liked this post, follow me for more of these 🙂
Posted on December 15, 2022
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.