It’s all in your head

Sometimes the best way to solve a programming problem is to get away from the computer.

See, I spent several hours yesterday struggling with a problem that just didn’t want to be solved, and by the end of the day I was pretty frustrated.  I was trying to add pagination to FeedDemon’s newspapers, which should have been simple, but it turned out to be trickier than I anticipated (it’s a long story).

Finally I gave up, and decided to go work out to get my head away from the computer.  On the way to the gym the solution to the problem suddenly hit me – and I wasn’t aware I was even thinking about it.  I sat in my car in the parking lot for a few minutes, then turned around and drove home.  When I sat down at my computer, the code flowed like it was just waiting to be typed.

I know several other developers who have had similar experiences.  We’ll struggle for hours on something, only to find that the solution comes to us when we’re doing something else (like sleeping).

16 thoughts on “It’s all in your head

  1. I’ve certainly had a lot of experiences like this when coding. I’ve had programming solutions suddenly pop into my head during conversations, showers and I’ve even dreamt a solution once.
    I made up an analogy about this years ago, using little people with flags… stay with me. The conscience needs to know something, so gives the job to a guy with a flag, who runs off and looks it up (or works it out). When he’s got the answer he comes back and waves his flag. But if you’re distracted or busy then the chap with the flag doesn’t get noticed. However, when you’ve got nothing better to think about, and you’re staring around blankly, suddenly you spot the flag and get the answer.
    Well, it works for me.

    Like

  2. I’ve had the same experience a number of times; I’d walk away from some frustrating code for a short time and the answer would suddenly come to me without thinking about it. In fact, as ridiculous as it sounds, I think I’m often a better coder when I’m away from the computer.

    Like

  3. The shower; it’s always in the shower. Now if I could just convince my wife that cleaning up Sharpie on the shower door is better than me dripping into my keyboard…

    Like

  4. David,
    If *Weird Al* can code in the shower…
    (If you’ve seen his White & Nerdy video, you’ll know what I’m talking about. If not…go see it! :) )

    Like

  5. I’ve had this many a times. I actually use it now I know it works like that :-)
    When I have a hard problem that I haven’t been able to make progress on for over an hour I just drop it and go do something completely different. Then, usually, after a while the solution pops in my head.
    I think that when you’re so focussed on solving a particular problem, you’ve essentially chased your mind in a corner and it’s fixated on solving the problem while looking at it from a certain angle. Then when you stop thinking about the problem, your mind gets out of the corner and can wander around free. Then it looks at the problem from a totally different angle and you’re able to see a solution.

    Like

  6. Amen to that! Once I spent 2hrs struggling while some C code wasn’t compiling…. I went for lunch, came back, sat down…and the problem was right there: missing semicolon. :)
    I had a project once, and my solution wasn’t workign right. Then I dreamt about a way to do it. I went to work, and was like I doubt it’ll work but what do I got to lose… it worked!!

    Like

  7. I believe this has to do with the physical process of learning. It is just the brain starting to connect those neurons. I have had this with everything related to learning. Learning is problem solving and programming is learning how to solve problems. But I especially had this when learning new maths or a new vocabulary (latin for example). It is just that in the moment of learning I cannot “get it”. Then, after a while, sometimes days later when not even actively thinking about it anymore, it suddenly “plops” into mind. And then you always ask yourself how you couldn’t have thought about this earlier. Well, you couldn’t have because the physical pathways and connections in your brain just “weren’t there” yet.

    Like

  8. Heh, so familiar, that I actually refuse to spend too much time on either problem. If anything is giving me problems for more than half an hour, I give up and continue tomorrow. It’s usually resolved in 5mins.
    p.s. Sorry for this abuse of the comment, but…There is a problem in FD with password-protected feeds. I have only one, DaringFireball.com members feed. Click on “update all” icon always asks me for user/pass, even though it is written in URL. Update on the feed itself does not asks for user/pass. I’m using 2.0.0.25.

    Like

  9. The shower is a good way to solve a problem, as is spending a few minutes in another part of the bathroom…
    Possibly the best is getting a haircut and having a scalp massage as part of the rinsing step.
    Above all, though, I think the key is not being near a computer. If you’re at your desk and you start to get an idea about how to fix something, it’s almost impossible to not start banging away at your keyboard. in the shower, etc, there’s no keyboard and so you think things through a little better.
    Basically – computers are bad for developing code…

    Like

  10. I can’t even count how many times I’ve woke up at 3am with the solution to a programming problem. It happens to me all the time. It’s pretty amazing how the brain works–although all that racing of my mind does make it hard to fall asleep at times…

    Like

  11. i find cigarette breaks the best source of inspiration when i’m stuck on something. it’s amazing how much simpler things are when away from the screen.
    i reckon, due to their frequent breaks, smokers make the best coders!

    Like

  12. that’s one reason I keep a pad of paper with me in the car… (yes, I pull over to write)… solutions to problems I’ve been wrestling with during the day come to me when I’m not staring at them anymore… just need to give you brain time to process in a less-focused way sometimes.

    Like

Comments are closed.