I usually find that after a couple of hours "in the zone", I need to take a break, get some fresh air and get a new perspective. Often, these breaks allow me to generate a solution to some stumbling block that was preventing progress. If, instead, I continue to pound at the code, I start to get sloppy, make mistakes and get more and more frustrated, which leads to a vicious cycle whereby I get almost no productive work done.
I maintain that some of my best work is done during my lunch break, when there is no computer in sight.
What are your experiences with optimal lengths of coding sessions and how do you structure your time to achieve this?