DEV Community

Amir Boroumand
Amir Boroumand

Posted on

3 Things to Do When You Can't Figure Out the Code

Take a break

Step away for a few minutes and come back to it.

Challenge your assumptions

You may be going down the wrong path because you are assuming a method or class works in a particular way when it actually doesn't.

Ask a colleague for help

Don't know who to ask? Check the Git history of the file to see who's worked on it recently.

Discussion (9)

threedeeprinter profile image
Dan Benge • Edited on

Start writing an email to an imaginary person, explaining the issue and what you've done.


If you really want to be fun, put a Teddy Bear or other stuffed animal on your desk and explain to your friend the problem you're having. AKA "Teddy Pair Programming"

Either of these two things will probably have you realizing the solution during the middle of your explaining.

sudiukil profile image
Quentin Sonrel

110% agreed. Another alternative is to start writing a question on StackOverflow (or equivalent). I tried it a couple times and figured out the solution by myself while describing the problem. And if it does work you can just send the question for real !

tedhagos profile image
Ted Hagos

I like the first one best "Take a break". The brain is mysterious thing. It's marvelous how it can come back fresh after a break, then you can spot obvious problems (it may just be eye-fatigue, but I really think it's the brain)

enriquemorenotent profile image
Enrique Moreno Tent

It has happened many times, that when I did not know the answer to a problem I was having, I would direct my attention on StackOverflow in search for help. In there, quality posts are required, if you do not want your question shut down, so I would think carefully my query, and start writing it down on the input field. And as this question starts taking form... suddenly I realize there are things that I have not tried. Things that could very easily be the cause of my problem.

This experience makes me realize every time, how much can learn by formulating question.

chiangs profile image
Stephen E. Chiang • Edited on
  1. Explain each line in comments
  2. Use breakpoints in debugger to understand flow and values
  3. Explain to colleague what you know, then ask... Often before you get to the ask part you might have figured it yourself.
  4. If still unclear, go for a walk, run, go boxing, take a nap then come back. Sometimes that aha moment comes when you least expect it.
ifewalter profile image
Ife. Walter every time.

michael profile image
Michael Lee πŸ•

I agree with point 1! Sleeping on it usually helps me. Sometimes, if it isn't mission critical, coming back to it after a few days.

Thanks for sharing Amir!

cathodion profile image
Dustin King

Writing things down or drawing diagrams on paper sometimes helps me figure things out.

andrekelvin profile image
AndreKelvin • Edited on

I agree. The human brain is kinda like a computer too, if it's not functioning properly REBOOT