DEV Community

Cover image for What do you do, when you are stuck?

What do you do, when you are stuck?

Ben Dowen on March 28, 2019

I've been struggling with bug I've been trying to investigate now for over 24 hours. At this point, I need a break, so much so I'm considering goin...
Collapse
 
desi profile image
Desi

Rubber ducky debugging!

Other than that, writing out in psuedo code what I want to do. Since I'm usually doing this for javascript problems, writing it out helps me see which functions I should probably use to achieve whatever I'm looking to do.

Collapse
 
dowenb profile image
Ben Dowen

Thanks for sharing Desi. I like the idea of using psuedo code. I'll give this a go.

Collapse
 
matthewbdaly profile image
Matthew Daly • Edited

Going for a walk is my personal favourite. Or if I can't do that, make a cup of tea. Something that gives me a chance to stop actively thinking about the problem.

I highly recommend the book Pragmatic Thinking and Learning for more details, but essentially there are two "modes" of thought you need to engage. One is the linear mode, essentially your inner monologue, which is useful for working through problems logically. The other, referred to in the book as R-mode, is more unconscious, and works like an asynchronous search engine in that it will work away in the background unnoticed and then suddenly return ideas.

Actively using the linear mode stops R-mode from working, but if you go do something else and switch off your l-mode, it has a chance to run.

Very often I've been stuck on a problem, then gone home or out to the shops to buy lunch, and very quickly been hit by the answer, or at least a new idea.

Rubber duck debugging is another good one. Explaining the problem to a colleague will often lead me to the answer even without any input from them.

Collapse
 
dowenb profile image
Ben Dowen

Thanks Matthew, lots to think about there! When I get a chance I like to work in a pair, but it isn't always easy as I'm primarily remote.

Collapse
 
matthewbdaly profile image
Matthew Daly

Rubber duck debugging can work with pets or inanimate objects (it helps if it's something you can anthropomorphize, such as a stuffed toy), or a non-programmer. It's the act of explaining it that gets your brain working.

Thread Thread
 
dowenb profile image
Ben Dowen

I really should give this a go. I spend a lot of time alone in my home office. I could speak with an inanimate object quite easily without being interrupted.

Collapse
 
zacharypatten profile image
Zachary Patten

When I get stuck... I usually ask a friend about my code. Even the process of me explaining the code to him/her may get me in the mindset I need to be in to detect a bug.

However... Probably the longest time I've ever been stuck on something was trying to find a way to perform mathematics on generic types in C#... I worked on this topic for months before I found a way to do it. I actually used generic types, runtime compilation, and delegates. :) I was only able to see this solution after exploring topics that were (at the time) outside my comfort zone. So you need to push yourself at all times to learn.

github.com/ZacharyPatten/Towel

Collapse
 
lankydandev profile image
Dan Newton

I think my best ideas to problems I spent a whole day struggling with have always came to me on the commute home. Whether that was the 30 min walk home from university, 5 min walk from my office to my flat or my current 1.30 hour commute from work.

As others here have said and many other people as well, doing something simple and mindless is sooooo helpful to get some ideas to pop up.

On commutes home, I've had to whip out my phone to write down an idea I just came up with, just so I don't forget it when I'm actually at work the next day.

This is what helps me the most. That being said, I agree with most of the other comments here and they also provide good other ways to climb out of a debugging whole!

Collapse
 
juanfrank77 profile image
Juan F Gonzalez

I do a whole lot of things when I get stuck, not particularly helpful most of them. Once I got stuck writing a unit test for AngularJs and it took me like 3 days to understand the problem and another 5 to reach the solution.

Without looking at what others have suggested I'd say the obvious first, google it. Also if you can ask teammates or other people on the floor, distance yourself from the problem for a moment like go for a walk.

Also, talk to the rubber duck or in the most desperate situation (like I did) get help from an experienced mentor to solve the problem you're facing.

Collapse
 
saraahmed626 profile image
Sara °°°

For me i don't have that fixed routine when i get stuck.
But taking my mind off that issue completely(trough whatever: sometimes just sleeping can do the work ) is so helpful, and the solution comes right after getting back, or suddenly pops up during that break.

Collapse
 
jaffparker profile image
Jaff Parker

Usually this happens when I try a new library or there was an update to the one I use. Then I end up spending 7 hours reading how that library works and tracing the APIs that I use in their sources... Not the best approach becuase it leaves me too exhausted to do anything else, but at least I REALLY learn the libraries :D

And also the gym, or at least a walk outside. It's really meditational

Collapse
 
dowenb profile image
Ben Dowen

Excellent. I especially like the reminder to split the problem down, I definitely need to do this!

Collapse
 
healeycodes profile image
Andrew Healey

If talking to others isn’t an option then I work backwards and disbelieve my assumptions about the problem one by one.

Collapse
 
dowenb profile image
Ben Dowen

Excellent, this sounds useful. I'm going to give this a go. Thank you.