With broadband internet being what it is, and tabbed browsing, and the crazy amounts of very entertaining social information sites, and someone down the hall asking for help with the printer (combined with your desire to be useful), and the coder next to you showing everyone clips from comedy central, and the nasty habit of wanting to delete files and defrag your system, and oh yeah, the work that you are suppose to be doing which you're really not sure about since you have three different potential higher ups that all think their project is the highest priority, HOW ON EARTH DO YOU STAY ON TASK AS A PROGRAMMER IN A WORLD LIKE THIS?!
Self discipline, headphones, the close browser button.
Also, tracking what you are doing throughout the day is a great way to see where you waste most time. It gives you metrics to help you improve. TimeSnapper is good for this.
http://www.43folders.com Get tips from there.
A few things I have done in my workday is close Outlook for 2 hour spans, close the door and/or put on headphones. Try to have a clear idea of what you want to do during that 2 hours, and just do it.
Finding the power to avoid the very thing you're doing right this moment
There is a related discussion with some useful information:
http://stackoverflow.com/questions/44285/how-do-you-make-yourself-productive-doing-hobby-projects
- Firefox extension for blocking websites you tend to waste time on: LeechBlock
- Pick a project and try to focus only on it for an hour or two; see how far you can move the ball down the field, how much progress you can make on it.
- Tell the guy watching videos to fix the printer!
- Ok, seriously? Politely ask the guy to stop showing you videos.
The best answer is to start smoking and use it as an excuse to take a break.
just kidding :D
On a serious note, please don't. They are expensive.
Anyhow, headphones are the best. There is nothing that motivates me more then a 20 Oz coffee and two white chocolate chip cookies from the store next-door with studio headphones blasting anything from Slipknot to Oomph or In Flames. I also take regular two-five minute breaks (to... stand outside) every 30 minutes to an hour to stretch my legs and think about what I am actually programming. Sometimes I may take a notepad out with me so I can sketch something down without dealing with all of the crazyness of a retail/computer repair shop.
In fact, it is easier for me to sit down and say "What am I programming? How can I make it be future proof and work well with the rest of the system that has not even been built yet?" then to stare at a blank page in my IDE. Of course, I am a single developer on most of my projects - so I don't have management or lead developers to worry about.
Ultimately, you have to find the best combination of things that get you working then repeat that every day. Don't ignore others, but make sure to make it clear to them (as long as they are not your bosses) that you are working on something that is priority and cannot be bothered by anything less important. Don't be the go-to guy for the printer if it takes you off task.
Do one task at a time. When a progress bar is going .. just sit there and wait for it. Do not read email, do not visit Stacko, do not pass Go, do not collect $200. When the progress bar finishes, continue with your task. You will finish sooner this way.
If anything, read a book or something that won't give you more opportunities to start another task.
I use Virtual Desktops using SysInternals Desktops (http://technet.microsoft.com/en-us/sysinternals/cc817881.aspx).
With this, I can have email on one screen, personal websites on another, and my development environment running on a third. As long as I don't see my email notifications or web browser I can stay focused. While I'm compiling or running tests I switch to the other Desktops.
Out of sight, out of mind. But still find windows of opportunity for scratching the itch.
Eschew distractions. Read your email twice daily and close the application otherwise. Let your calls go to voicemail unless you're ready to answer them. Let your IMs sit and blink in the tray until you're ready to read them. If anyone has something really important to tell you, they can walk.
Pair programming. It's a lot easier to exercise some restraint with another programmer there focused on the same task as you.
I don't think I have ADD, but I do like to avoid trivial distractions. Here are some of the things I do.
If you have an office with a door, shut it!
Pick two times per day to be available for phone calls. Then let everyone on your team know those times and ask that they contact you via email unless it's an emergency. (Building on fire and flames approaching your office.) Then do your best to avoid answering the phone any time other than your designated "phone" times. Admittedly this works best if you aren't at the bottom of the chain of command!
Use noise cancelling headphones. I use Audio-Technica ATH-ANC7 headphones. They do a good job and I really like the detachable cord.
Keep your desk clear of everything that doesn't relate to your CURRENT task. I have a L shaped work area and keep my primary work surface clear by using the other leg of the L to hold everything else.
Control the light in your work area if you can. By concentrating light only where you need it, you avoid being distracted visually.
Keep a list of "stuff I want to do" in whatever you use to organize notes. Then when you feel the urge to look up the lyrics of that new song you heard on the way to work, you can jot it down on the list and look it up later instead of right now. This takes some discipline, but having a list handy helps.
I have a big GraLab timer on my desk. When I start off on something that might be distracting (StackOverflow for sure!) then I set the timer for the amount of time I am willing to spend on it. Then when it goes off (LOUDLY) I force myself (usually) to go back to my primary task.
I have a lot of reference books, but there are really only a half dozen that I use with any frequency. I keep those within arms reach so I don't have to get up and get them.
It's going to sound like blasphemy.. but hear me out.
- Close your Email.
- Shut down IM (or set to away and ignore anything non-critical)
- Pick some music that you can work with and toss on headphones. I prefer electronic music because it tends to fade more easily into the background for me (and I'm still a raver at heart)
- Ignore people who try to distract you whenever the headphones are on.
- Remove the headphones once an hour and schedule a break. Spend a MAX of 10 minutes checking Email, StackOverflow, Digg, Reddit whatever
Once you get into this habit, people will leave you alone more since they know that "headphones on = won't pay attention".
You'll be able to keep up with everything you do now, you'll just use your time better. Instead of constantly switching back and forth whenever a new email comes in or question pops up on SO, you'll set aside time to focus on each thing in turn rather than trying to process them all at once.
This appears to be a similar question in some respects:
Asperger’s Syndrome - What do you do to cope at work? What accomodations has your employer made?
It isn't exactly the same, but I would think solutions for one may be applicable to the other in some cases.
Time-boxing helps for many people. It does for me.
As many posts have already alluded to: remove all distractions that you realistically can. If you remove the temptation to get off task, then you'll have an easier time focusing.
And if you really are having trouble staying on the task at hand, perhaps you should write down what you're thinking about. Is it really the most important thing to be doing right now?