Yesterday I spent a good part of the afternoon trying to fix a bug, which I thought to be trivial. I was going around in circles, not having a clue what was wrong. Rewriting large parts of the code. Checking on SO. Still no joy.
So I went home, walked the dog, watched a little TV and just before I went to sleep, bingo I realized the obvious mistake I was making. This morning it took about 10 minutes to fix.
While I was home, I wasn't actively thinking about the problem. Yet taking myself out of the situation enabled me to solve it.
It isn't the first time it has happened, and I know that it is a fairly common way to solve a programming problem. I have even heard of people dreaming the answers.
Why does this work?
Perhaps more importantly, is there a good guide as to when you should take a break from a problem, how long should the break be, and after how long does leaving a problem stop being effective?
I suppose I am trying to work out how to optimize this subconscious processing (or whatever is going on)