In many office environments, focusing on a single task is next to impossible. In the cubicle adjacent to yours, two colleagues chat about the latest blockbuster movie; another coworker comes to you voicing frustration about a bug report; your boss invites you to an ad-hoc meeting (an offer you can't refuse). A slew of other distractions have nothing to do with the people around you; it's all too easy to check your email, IM chat or text with friends, or look at the latest pictures on Facebook posted by your best pal from high school.
Interruptions are costly. But there are ways to minimize the damage and get the job done, so you can feel good about having completed what you set out to do.
Wait, what were we just talking about? Oh yeah, distraction. What do we know about that subject?
The Nature of Distraction
Research strongly suggests that interruptions produce an "attention residue" that impairs your capacity to work on a subsequent activity.  As you've probably guessed, attention residue is unfinished business that nags at you and prevents you from fully focusing on anything else.
Suppose you get stuck on a programming problem, and you decide to check your inbox just to take your mind off the frustrating issue. The first message you read is a nasty complaint from a client on an unrelated project. Now you're unable to focus on either task, because your attention is fragmented by the two dangling issues. Human nature dictates that until you've resolved a problem (or at least brought it to a resting point), you'll just continue thinking about it.
The good news is that attention fragmentation is reduced when you move between tasks within the same "working sphere," which can be thought of as a project. The "working sphere" might also be a set of interrelated tasks toward a particular goal, performed by a fixed set of people, using a particular set of tools, and within a specific timeframe.  
Evidence also suggests that if you juggle tasks that are within the same working sphere, you can actually be more productive, presumably because ideas associated with the different items in the same sphere feed into each other and stimulate new thinking.
Still other studies have shown that it's productive to take your mind off work from time to time. If you're doing creative work, physically moving away from your task, such as by getting up and doing something else, may allow you to incubate ideas.
Given these research findings, and based on my own observations of best practices in time management from leading executives, three traits seem to account for why some people are able to focus better than others:
- People who concentrate well use a set of tools that help them to filter out distractions.
- These people also have better attitudes about the work they're doing, so they don't seek out distractions.
- Over time, people who focus better make a habit out of using tools and managing their attitudes, so the whole process of filtering out distractions and concentrating becomes second nature.
Remember that even when distractions come from the outside, you alone decide where to focus your mental energy. The trick is to apply tools and improve your attitude toward your projects and your approach to bringing them to completion.
Five Tips for Focusing Your Effort, Starting Today
Robert Benchley once said, "Any one can do any amount of work, provided it isn't the work he is supposed to be doing at that moment."  Benchley, a humorist who wrote for New Yorker and Vanity Fair in the 1920s and 1930s, went on to say that he had worked out a system in which he made a list of important things to do and fooled himself by putting what was really important at the bottom and convincing himself that the topmost item in the list was what he should be doing. Naturally, he put off the top item and instead worked on those items he listed as less important.
I personally am unable to psych myself out enough to get such a system to work for me, so I've had to develop other methods, which I share with you here:
- Make a "top five" list. On a small piece of paper, jot down the five most important things for you to do today. Include personal as well as professional tasks, and don't worry about ordering the items by priority. Keep your list down to no more than five things; it's even better if you can limit it to just two or three truly important tasks.
- Divide your work into manageable chunks with clean stopping points. Rather than try to tackle large projects all at once, break the work into small pieces you can knock off with relative ease. Focus on a single chunk until you bring it to completion. Take a break and congratulate yourself before moving on to the next piece.
- Separate tasks by context. Group work by context to avoid jumping around between working spheres. A working sphere might consist of all tasks related to a given deliverable, it might be administrative tasks, or it could be managerial duties.
- Maintain a "slush fund" of short tasks you can knock off just before or just after a break. Note all the little bits of work that need doing, but aren't related to any of the big items. Don't make the mistake of working on these short tasks while you're supposed to be doing the big ones. Tackle the items from the "slush fund" only just before or just after a break. You'll feel better for having finished the little things, which will improve your attitude when you work on activities that require greater concentration.
- Make clean breaks. Breaks enhance job satisfaction by giving you necessary "play time" and by alleviating fatigue and stress. They also provide opportunities for ideas to swim around in your unconscious, bubbling up when least expected. Incubating ideas in this way is especially important when your work requires creativity, as software engineering does.
Put your "top five" list in your pocket; pull it out and look at it from time to time. In the fog of a modern workday, it's easy to forget why you got out of bed in the morning. This list will remind you.
Don't worry about completing all the items on your list. You usually won't. Some things take longer than you thought they would. Other things get squeezed out by unexpected events. Still other activities are ongoing in nature and impossible to complete in one day. The sole purpose of the "top five" list is to remind you of what you consider important.
Once you develop the habit of working on one small bit at a time, try to improve your methods for breaking up big projects into small pieces. The better you get at identifying the components, the better you'll be at finishing big projects. "Divide and conquer" has always been a good strategy for taking on any large and scary challenge.
Avoid springing back and forth between contexts. Instead, try to make significant progress in one sphere before moving on to a different sphere. You might also take a break before switching working spheres.
Get up every hour and walk around for five minutes. Take one longer break in the morning and one in the afternoon. Break for lunch and avoid eating at your desk. Set aside time to chat with colleagues about topics not related to work, but be careful not to bother other people or let the chat sessions spin out of control. After all, you don't want to be the one who wears the scarlet letter "D" at the office (where "D" is for Distracter)—a label to be avoided at all costs.
Consider these five tips to be a mixed bag of tricks that you don't have to use in combination. Pick the ones that are most appropriate to your projects or work style. I hope you'll find that they help you to focus your effort.
Now if you'll excuse me, I'm going to get back to what I was supposed to be doing.
 Sophie Leroy, "Why is it so hard to do my work? The challenge of attention residue when switching between work tasks", Organizational Behavior and Human Decision Processes vol. 109, issue 2 (July, 2009), pp. 168–181.
 Víctor M. González and Gloria Mark, "Constant, Constant, Multi-tasking Craziness: Managing Multiple Working Spheres," Proceedings of the SIGCHI Conference on Human Factors in Computing Systems (April, 2004), pp. 113–120.
 Gloria Mark, Víctor M. González, and Justin Harris, "No Task Left Behind? Examining the Nature of Fragmented Work," Proceedings of the SIGCHI Conference on Human Factors in Computing Systems (2005), pp. 321–330.
 Robert Benchley, "How to Get Things Done: One Week in the Life of a Writing Man" Chicago Tribune (February 2, 1930), p. 6.