How long does it usually take? What kind of things do you do to ensure you'll come back smarter and faster?
I'll often get hit with solutions to ideas at the worst times to write them down:
In college one of my instructors said that this is the reason why it's always best to start projects as soon as you can, because a creative mind is never truly "off".
If you have 3 projects, don't do them in this sequence:
project 1 -> project 2 -> project 3
But rather, even if you only spend a few minutes do this:
start project 1 -> start project 2 -> start project 3 -> finish project 1 -> finish project 2 -> finish project 3
Because after you've started it, it sits on the back burner, you might not even be aware or conscious that you're thinking about it, but maybe you'll be eating dinner and an idea will hit you. But that won't happen if you haven't even started the project yet.
It's actually part of why scheduled breaks are an integral part of my coding process. Alternating between projects, modularizing projects and working on different sections in turn, just plain getting up for a walk to clear my head.
It is all part of making sure I don't get bogged down on the simple projects. You cannot be productive sitting there working non-stop for hours on end. Admittedly, there ARE times you "get in the groove" and the hours fly past, but for the most part it helps to stop BEFORE you reach that point of frustration or overthinking one little piece of the puzzle so you can come back at it with a clear head.
If nothing else it's better for your health too to just get up and get out. Coding is a sedentary lifestyle, and the coder's diet of Coke and Crisps certainly doesn't help.
So PLAN on getting up every two hours to three hours, walk around the office, jog around the building... do something else. Even just five minutes away from a project can boost your productivity when you come back.
Couple of thoughts...
One is that when you work for a long period on something you get sort of code-blind and go past the threshold of diminishing returns. You aren't really seeing what you're looking at any more, you're seeing what you think should be there. It will take you many hours to do a real hour's worth of work. When you come back fresh later on, you often pick up the problem very quickly.
Another related thing is "rubber duck debugging", where the act of describing the problem to someone else makes you clarify the situation in your own head... so you suddenly realise what you're doing wrong. The other person didn't do anything except sit and listen. The theory goes that you can explain things to a rubber duck (some say a teddy bear) sitting on your desk; get the same result without bothering someone.
A simple, quick solution can simply be to go for a walk (10-15 minutes). Get away from your desk, get some air, stretch your legs, let your attention wander on to other things. When you come back you often solve things pretty fast.
Plus I also recommend having a sort of standard mental script to check the basics.
Like Joe said stepping back helps a lot on refocusing on the actual problem and thus find a solution. My head is always working in background on the problem even in the off-work time. That’s a risk if the job :). Mostly my problems get solved during sleep over night or under the shower.
Sometimes just stepping out to check the mail works. Sometimes it's an overnight, sleep on it kind of thing. Every once in a while, the solution comes in a dream.
Ben Buchanan (200ok)
I make some bits of the web.
Sandeep Panda
co-founder, Hashnode
Yes... so many times. Whenever I am stuck with a problem for more than an hour, I take a break. I usually just walk a bit, sleep (if it's late night) or just engage myself with some other activity. Usually, when I am away from computer I imagine various solutions and when I am back to work, 90% of the times I fix the problem. :)