DEV Community

What's the best thing to do when you've run into a debugging dead end?

Ben Halpern on December 17, 2019

So you've hit a wall. What is the best course of action in this situation?

Collapse
 
thatonejakeb profile image
Jacob Baker

Turn off the computer and go for a walk.

Collapse
 
drewtownchi profile image
Drew Town

This is the easiest and best thing to do. Let your brain work away from the screen. The amount of problems I've fixed by not working on them for a bit is staggering.

Collapse
 
ronaldoperes profile image
Ronaldo Peres

Yes, this is one of the best thing to do.

Also if you get stuck like for 20 minutes, ask a friend for help.

Collapse
 
seniru profile image
Seniru Pasan Indira

Good answer, sometimes time can give you the solution

Collapse
 
kmwill23 profile image
Kevin

Sleeping works too! And video games.

Collapse
 
s_aitchison profile image
Suzanne Aitchison

Make a cup of coffee > Explain the problem to someone else > Have a mid-sentence brainwave > Run away back to desk and fix in seconds > Have existential crisis about why that took so long

Collapse
 
danondso profile image
Dublin Anondson

This so much. There's just something extra about talking to a person instead of a duck.

Collapse
 
s_aitchison profile image
Suzanne Aitchison

And the face-palm moment that inevitably follows 😂

Collapse
 
cassidycodes profile image
Cassidy

This always works for me too! I try to explain the problem like ours the first time I’ve ever seen it.

Collapse
 
kayis profile image
K

I am going to solve this problem with weed

Collapse
 
nestedsoftware profile image
Nested Software • Edited

I think this summarizes my usual process for debugging tricky problems:

  • When working through various scenarios, make sure to carefully document each step. Make sure to alter only one thing at a time and check all possible combinations of things that may be causing the problem.

  • Break the problem all the way down to its fundamentals - sometimes that may mean starting from scratch and adding code bit by bit until the problem manifests itself.

  • Take a break: It's amazing how new ideas can come along when you're taking a walk or are in the shower!

  • Research: Look for answers online

  • Ask for help: Ask someone who may be able to help, either online or in person

  • Workaround: Is there some way to solve the problem without attacking it directly? Maybe there is a way to solve a slightly different problem that will still produce the desired results, or at least get close enough to get past the current bottleneck.

Collapse
 
karataev profile image
Eugene Karataev

Start asking questions: Why am I doing this? Am I happy? I can't solve this, I'm an impostor. I better work with wood or open a bar..
Oh, that was a typo! Great, keep coding

Collapse
 
buphmin profile image
buphmin

Ask someone else too look at the problem with you. Sometimes they will see something you didn't since they don't have a ton of assumptions on how it will work.

Collapse
 
olistik profile image
olistik

Stop locally and restart from the simplest working context.
It's almost like performing a git bisect.

0: disable/comment almost everything so that you have the simplest context;
1: test if the context behaves like it's supposed to behave;
2: if it does then re-enable/uncomment half of the things back and GOTO :1;
3: if it does not, then if the problem is self-evident, fix it and RETURN 🥳;
4: if it does not, you already know that the things just restored are responsible for the issue. You can pinpoint the issue even further by disabling/commenting half of the things you have just restored and GOTO :1;

The key point here is that you waste a few minutes in order to get to :0 but avoid wasting several hours finding a bug that is probably way above the context you're looking at.

It can appear vague but it's a debugging process that can be performed in a wide variety of contexts, not just source code.

Collapse
 
dfockler profile image
Dan Fockler

I always start with asking myself "What assumptions am I making about what's happening?" Most of the time this leads to me realizing I don't understand how something is actually working and that my assumptions created some false understanding. Bugs on computers are almost always deterministic at small scales. So, if you can dive far enough down the abstractions you can find the bug.

Collapse
 
tarasnovak profile image
dataPixy 🧚‍♂️

I highly recommend a cup of jasmine tea w/honey & meditation sess.

Collapse
 
karfau profile image
Christian Bewernitz

If you dont want to leave your train of thoughts by leaving the desk/computer (yet):
Use the help provided by rubber duck (can also be a text editor or colleague if you prefer):
Explain everything you did so far, as you would need to in a stack overflow question or thorough bug report.
In most cases I do that, the missing piece get's obvious.
If you have the patience to write it down and it doesn't help you can of course ask that question here or somewhere else, or file that bug...

Collapse
 
fossheim profile image
Sarah

Take a break. I either:

  • Go for a walk
  • Work on another issue
  • Get coffee/water and take a social break
  • Have some food

And then when returning to it with an empty head, I sometimes start from scratch again depending on the issue.

Also breaking the problem down in separate tasks, and logging everything along the way. And when things are split up properly, comment out everything and try each function by itself.

Collapse
 
fjones profile image
FJones

Try a different approach.

Been using your debugger all throughout? Try some dumps - even just to confirm what your assumptions are. The inputs really are in that range? This particular function returns what I expect?

Dumps didn't work? Static analysis. Write out the branching. Look for things that seem overly complex or too easy - try and rephrase them in pseudo code and, again, confirm your assertions.

Still no idea? Run through it backwards. What needs to happen so you get the expected result? What would have to happen to produce the result you're seeing?

Break the problem down. Talk to someone else about it. Take a walk around the building.

Essentially: change your frame of mind and reference. Work a different angle until the suspicion kicks in - the tiny moment of "wait... Surely it can't be that!"

Collapse
 
jwp profile image
John Peters

Keep at it no matter what, but try to get rest before next session.

We had a bug once that took 1.5 years to determine the root cause.

And we had another one, where the vendor of the software told us after a year of reporting the issue, they could not find root cause. The main reason on this one was that nobody knew how to read a system dump trace which was our only way to show them the error.

Collapse
 
schwad profile image
Nick Schwaderer

Something I heard from a mentor in a coding school five years ago.

Ask yourself:

Could it be simpler?

The number of times that I have lost hours of awful rabbit-hole coding when it was just a typo. Or my server wasn't running. You wouldn't believe it. This advice applies for me time and again.

I keep morale up by reminding myself I've made it this far coding, no bug has destroyed me (yet).

Collapse
 
fultonbrowne profile image
Fulton Browne

Turn your computer off, scream, get some coffee and listen to music until you solve your problem.

Collapse
 
berkmann18 profile image
Maximilian Berkmann • Edited

Have a break.
If it's late or you are tired, go to sleep.
If it's time to eat/drink (or your body is need of it) then get away of the keyboard and eat/drink.

Other solutions include:

  • going for a walk
  • playing a game or doing a leisure activity
  • exercise
  • rubber duck debugging
  • asking for help
Collapse
 
peacefullatom profile image
Yuriy Markov

Take a break. Do something else.

Collapse
 
kmwill23 profile image
Kevin
  1. Get coffee
  2. Complain to my neighbor about how it's impossible.
  3. Then realize you told them to remind you nothing is impossible anytime you said it was.
  4. Drink coffee
  5. Start plotting the Frankenstein code to log more data or attempt to short-circuit.
  6. Come back the next day and realize the problem was so simple.
Collapse
 
swarupkm profile image
Swarup Kumar Mahapatra

Rewrite the whole module (if you have time). Also, make use of git so that you can revert you code.

Collapse
 
arist0tl3 profile image
Sean (Diddy)

Ask for help! (And not on SO...)

As someone who has been a solo dev on a lot of projects, just having a second pair of eyes on something is invaluable.

Keep in touch with devs that you trust so that you can send a snippet, preview, etc. and get their opinion.

It's kind of like a puzzle sometimes: you can keep staring at the same pieces for all eternity, and a friend could walk into the room and see the piece you've been looking for right away.

Collapse
 
leob profile image
leob • Edited

Take a break, walk, cycle, sleep, come back tomorrow :-)

But when it's mega urgent or you're super fanatic and determined to "just solve it" then following this advice is hard.

An alternative (well, one of the many alternatives) is to "google it". It continuous to amaze me how many problems can be solved in that manner.

To optimize this work on your "vocabulary", the more words/synonyms you know (and the more "background knowledge" you have), the greater the chance of finding something - use a certain generic term and you'll often find nothing usable, but use a more accurate term or focused synonym and it's frequently "bingo".

Collapse
 
exadra37 profile image
Paulo Renato

Try Rubber Duck Debugging technique:

The rubber duck debugging method is as follows:

Beg, borrow, steal, buy, fabricate or otherwise obtain a rubber duck (bathtub variety).
Place rubber duck on desk and inform it you are just going to go over some code with it, if that’s all right.
Explain to the duck what your code is supposed to do, and then go into detail and explain your code line by line.
At some point you will tell the duck what you are doing next and then realise that that is not in fact what you are actually doing. The duck will sit there serenely, happy in the knowledge that it has helped you on your way.

Note: In a pinch a coworker might be able to substitute for the duck, however, it is often preferred to confide mistakes to the duck instead of your coworker.

Collapse
 
fdocr profile image
Fernando • Edited

Start a draft question on StackOverflow (or similar). That’s my last resort, because it forces me to run through a mental checklist along the lines of:

  1. Really make sure there’s no duplicate question out there (with an answer 🤞🏼)
  2. Write a concise explanation of the problem (helps understand the problem better if you can explain it)
  3. Look for evidence other people will eventually ask for (i.e. logs, print screens, reproduction steps, etc)
  4. Continue to work on the draft by asking yourself follow up questions others might eventually ask you (i.e. “have you checked the config file?”, “have you read the man page to look for other options available?”, etc)
  5. After double/triple checking the draft and still not finding a solution, post the question (internet strangers help each other everyday)
  6. Feel guilty for not doing enough research, so you keep trying and might even solve the problem on your own after coming back fresh another day, if the question hasn’t been answered yet (I wouldn’t recommend the guilt part but that’s just usually me at this point)
Collapse
 
chrisrhymes profile image
C.S. Rhymes

Close all tabs in your text editor, get a cup of tea then it pops in your head out of no where

Collapse
 
chiangs profile image
Stephen Chiang

Step away, take a walk, go to the gym, or talk your process with another dev.

Collapse
 
garraxxi profile image
Orlando Ego

go to bathroom!

Collapse
 
cadams profile image
Chad Adams

Grab a rubber ducky and talk to it :D
Rubber Ducky Debugging

Collapse
 
warissarwarpk profile image
Chaudhary WS

Give yourself a while, let it where it is, do something else! I always press window+L & go out!

Collapse
 
davidchandra95 profile image
David Andrian Chandra

Throw all your plans and ideas. Start fresh. Start from basic. A walk to toilet might help

Collapse
 
rose profile image
Rose

I'm always astounded by how often something that seems impossible on one day ends up being ridiculously easy the next day. The human brain does amazing things when you sleep on a problem.

Collapse
 
sandordargo profile image
Sandor Dargo

Taking a walk!

Collapse
 
mohanarpit profile image
Arpit Mohan

Simpson backing into bush

Walk away; slowly & quietly.

Collapse
 
ajaymarathe profile image
Ajay Marathe • Edited

I usually take a break, and then after sometime I start debugging it 😂

Collapse
 
chaos0815 profile image
Christian Wolf

Rubber Ducking does the trick for me. Though it’s more a colleague than a rubber duck most of the times.

Collapse
 
ajaymarathe profile image
Ajay Marathe

Usually I take break.

Collapse
 
dhruvins profile image
Dhruvin

I just try to relax, take a deep breath and again start with very small debug steps.

Another thing I try out is take a break and browse through Twitter or Instagram and start out fresh again.

Collapse
 
perigk profile image
Periklis Gkolias

Go for a walk.
Then start thinking about potential scenarios that might cause the failure.
Then try to prove your hypothesis

Collapse
 
nimmo profile image
Nimmo

Go home for the day, by a long chalk. Easily the most effective debugging technique is a change of perspective.

Collapse
 
richardeschloss profile image
Richard Schloss

Come to it the next day. The answer sometimes miraculously comes to me in my dreams.

Collapse
 
emmabostian profile image
Emma Bostian ✨

Cry yourself into oblivion.

Collapse
 
emmabostian profile image
Emma Bostian ✨

Sorry I haven't had coffee yet, Ben

Collapse
 
brooksforsyth profile image
Brooks Forsyth

If it’s after 5pm shut the computer off go to bed early.

Collapse
 
xowap profile image
Rémy 🤖

Sleep then rubber talk it

Collapse
 
rusty_xx profile image
Grey_W I N D

I usually watch a movie and play vids. Just do something other than coding. You would be amazed

Collapse
 
vvilliam5 profile image
Williams Oluwafemi

Turn off the computer and CONSOLE yourself

Collapse
 
wolfhoundjesse profile image
Jesse M. Holmes

Ask for help.

Collapse
 
sonyarianto profile image
Sony AK

keep searching on Stack Overflow hahahaha, phewwwww

Collapse
 
mokshchaudhary profile image
Moksh Chaudhary

I tend to write the whole code again and be miserable :)

Collapse
 
tariqabughofa profile image
Tariq Abughofa • Edited

Leave you desk. Have a break. Discuss the issue with your colleagues. Try again. Repeat until I figure it out.
Also if not urgent switch to another task and get back to it later.

Collapse
 
alxsmora1 profile image
Alexis Mora

Switch to another project or take a break.