|Do you know where your variables are?|
Your analogy is excellent and on a subject close to my heart. Here are my thoughts and experiences.
In essence, I work as an IT consultant and you'll see from my homenode that I have the vast total of experience of about three months. To be fair to myself I have a total of about eighteen months of practical software development - analysis, design, programming and testing - experience. In my current build/test role I spend an awful lot of time doing things which I often feel get in the way of my developing clean code (shell scripts in this case) or testing it scrupulously - I have meetings to attend, phone calls to take, people to query for information, my boss to keep fed and watered etc... These are the minor everyday tasks which are the mosquitos.
I generally have about three main tasks on the go at once, all of which require a rotating schedule of my time; some more and some less. These are the bears which need shooting.
Where I feel that the analogy work is that you must focus through these annoyances to keep your aim on the bear. To (mis)quote...
"When a samurai is out walking and it begins to rain. He does not run for he knows that he will get wet. He continues to walk and enjoys the novelty of the experience."
On the other hand, talk of swatting the mosquitos I feel is not helpful as they are irritations which must be endured, however swatting them will never help, you simply have to deal with them and there will always be more.
Consider this: Every time you phone someone to get clarification of a point in some documentation or to get the results of a pending decision it is you who is sucking the blood of your coworkers, and yet you would achieve very little of any use if you never receieved this information - constantly having to revise code or regression test.
Essentially the point here is about learning to context shift with as little disruption as possible: Being able to focus absolutely on a single task is a hugely important skill in complex software development, but being able to switch between multiple tasks rapidly and easily is surely a skill worth developing, although there is always an overhead associated with it. It is not an easy skill to acquire and one which I am finding hard to get to grips with.
On the practical side, I shall say this: Keep a list of current tasks either in a notebook or on your computer desktop in notepad or emacs with percentages completed. Don't be afraid to tell people that you can't talk right now because you're busy - with the caveat that you call them back when you're at a natural break point. Divide up your tasks into atomic units - sections of a task which it makes sense to complete before moving on to anything else. In short, manage your time - a task at which most people are very bad. Not to develop these skills in parallel with your coding skills is what I would see as being the sin of false laziness - they will save you time in the long run.
Please, if this node offends you, re-read it. Think for a bit. I am almost certainly not trying to offend you. Remember - Please never take anything I do or say seriously.