DEV Community

Cover image for How to Debug Code (Without Crying)
Void⚡
Void⚡

Posted on

How to Debug Code (Without Crying)

Debugging code is harder than writing it

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 🎯

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 🙂

Top comments (2)

Collapse
 
fromshubhi profile image
Shubhi✨

Great share, thanks for sharing this, needed the most.

Also would like to add "Hours of debugging can save you minutes of reading the documentation"

Collapse
 
codewithvoid profile image
Void⚡

Lol yes.