Forget Pro-Plus or extra strong coffees, you don't need this or a trip down to Spec-Savers to help keep focus.  The answer is agile.

I'm not going to speak for other devs, but I have a seriously overactive mind.  Just as I get into 'the zone', I'll suddenly remember a piece of code I marked to refactor, or think of a  good approach to solve that issue with the Javascript popups, or maybe even I'll remember it's my wife's birthday in 2 weeks and I still haven't decided what to get her.  Just like that, I'm out of the zone; I have to go back, re-read where I am, and repaint that mental picture of what I'm trying to achieve. I'd guess this is something all developers experience quite regularly.

So what's the answer. Maybe spend 3 years on a Tibetan mountain in deep meditation to improve concentration.  Perhaps one of those herbal teas would work? Or maybe some form of lobotomy would prevent these lapses of concentration…  To be honest, if I was able to give myself perfect concentration I would never remember to get my wife a birthday present.  I think the real answer is to find a way to get back into the zone as quickly as possible once focus has been lost.

Here's where agile helps. When working in an agile way, you are always working on a story.  If you lost clarity about what you're trying to achieve, you simply go and pick up the card, read the acceptance criteria again, and quite suddenly you're ready to go again.  Additionally, you're only allowed to work on the story in-front of you, so you can't be distracted by stuff outside the scope of the story.

Another valuable tool for regaining focus is cucumber.  We write up a user journey in cucumber first, and if you forget where you had got to, all you need to do is run that feature and you're told what to do next in big red letters.

So, in summary, an agile developer is better at retaining focus than a Tibetan monk… no really!