Of course, the answer is self-discipline, time management, etc., but there are a lot of factors that affect how successful I am at that. Here’s what I’m watching properly during the times that things are really working well:
- Personal physical factors: I avoid caffeine, because it keeps me “awake” but destroys my focus. If I’m really focused, I simply won’t get sleepy anyway. I avoid all alcohol during the week, and avoid sugary things at night, because those both affect my sleep patterns and sharpness in the morning. Proper sleep also makes a huge difference to focus... if I only slept 3-4 hours, even if I’m wide awake things just don’t seem to get done.
- Project factors: an interesting project that uses my knowledge/skills but also brings in some new things is much easier to work on. Boring projects (just solving the same old problems again in a slightly different way), overly tedious/frustrating projects (like cleaning up someone else’s mess or working with really buggy APIs), or overly daunting projects (working with a new language, in a domain only vaguely understood)... that’s when I end up bouncing off the work into random other activities like a stone skipping off water.
- Work organization: I try to stop periodically to make priorities lists and to-do lists, and to break down tasks into smaller and smaller sections. It’s important for scheduling purposes already, but the mental benefits are also huge. You can hit lots of little goals to keep you going, like “just get this query finished, send that email, then I can break for lunch”.
- Breaks: get up and walk around when you’re stuck. Don’t just sit in your chair (or take a break by going off to check [a news site]) — walk around and maybe get some fresh air. Let your mind play with the problem and come up with some new solutions to test out before you go sit down again.
Now I just need to follow my own rules *all* [of] the time....
(...There are a whole pile of interesting sets of comments in that discussion, running the usual range from “can’t do it/give up” to “dead easy, do it like this” — JavaRob was different from many in not recommending stimulants, but he also missed what I see as a key point: take a real break every so often)