in reply to How do you code?

I sometimes visualize meters over my head like a character from The Sims. The most important being level of concentration. I try to identify the things that negatively affect that meter and manage them. For me, distractions as simple as a five minute random conversation with a passerby can scramble the stack in my brain and cost me a good 30 mins of productivity. Too many consecutive interruptions and I'll get too tense to easily regain focus.

I dedicate the early part of my day to eliminating distractions. Handle the e-mail, phone calls, voice mails and co-workers that just want to chat, and review assignments to my employees. Then I shut the door and let my office manager redirect anybody that comes knocking. I wouldn't hear them anyway with the headphones.

All distractions aside, I lay out goals for the day's work and get to it. Having set goals gets me focused before I even get started. The rest of the day usually flies by.

On the bad days, when the focus or creativity just isn't there, I find something productive but relaxing to do. I'll try out a CPAN module I saw and wanted to mess with, or spend a few hours with an O'Reilly book.

If I'm pathetically awfully unproductive, I'll compose long winded forum posts and go home to play Team Fortress 2.

sundialsvc4 touched on this, but I try to never mix home life and work life. I don't entertain myself at work, or work much at home, because then when I'm at work I'm subconsciously trying to talk myself into playing games, and when I'm at home I feel guilty if I relax too much because maybe I should be working instead. It's a guaranteed recipe for a period of burnout.