Over the years, I have settled on a system that best allows me to focus and be productive.
Work 45 minutes. 10 minute break. Work 45 minutes. 10 minute break. Work 45 minutes. Longer break. Repeat as necessary.
How did I come about this system?
Mostly by trial and error and observing my energy. I would notice that it would take me about 45 minutes of working on something to come up with a solution. For example, if I was working on a bug fix, from the moment I started to the moment I finished would be 45 minutes. I would feel good about accomplishing my task and would take a break to relish in the accomplishment and prepare for what I needed to do next.
After doing this system for a while I came across a study that found people can only focus on one thing for about 45 minutes. After 45 minutes, your mind starts to wander and you have a tough time remaining focused. A break helps re-energize your focus. (Unfortunately I do not recall where I read this. If I come across it again in the future, I will edit this post)
What about longer tasks?
Longer tasks are just broken down into smaller pieces. No matter how large the project is I break it down into something that can be accomplished in about 45 minutes. In fact, you need to do this otherwise the project would just seem overwhelming.
Sometimes I do want to keep working but I usually feel worse if I do. My muscles will start to ache from sitting so long. You need breaks. Standing up and walking around helps improve your circulation causing better blood flow to your brain.
During the breaks, I will usually use the time to think about what I want to do next. I try to turn this break time into planning/thinking time. Too often as programmers, we just want to do, do, do. It is important to spend some time each day thinking about and planning your work otherwise you may end up spending time working on something that is not important.
To make sure I take breaks, I use SlimTimer to time my work. I start by simply clicking on the task and when 45 minutes are up, I take a break. Sometimes I will go to 50 minutes if I just need a few more minutes or stop at 40 if I have accomplished my task already but it usually averages out around 45.
It is important to remain as focused as possible for the 45 minutes otherwise this system does not work. You must resist any temptations that may pull you away from your task. Stay focused on one thing. Turn off email notifications and IM and close your browser.
Give this a try for your own work. Use a timer but only time the periods you are focused and productive. When you notice your focus is slipping or you need to take a break, stop the timer and observe how long you remained productive for. Keep recording this information for a week or two and you will start noticing patterns about how you work.
Edit: Here is one reference I have come across from “How to Stop Worrying and Start Living” by Dale Carnegie (unfortunately no reference is given for this passage):
“Why is [rest] so important? Because fatigue accumulates with astonishing rapidity. The United States Army has discovered by repeated tests that even young men - men toughened by years of Army training - can march better, and hold up longer, if they throw down their packs and rest ten minutes out of every hour.”