Getting in the zone allows you to be in a state where you’re completely separated from the outside world. It’s just you and the computer. Your fingers against a horde of bits. You know you’re in it when you notice 2 hours later that someone has walked inside the room you’re in.
Here are 5 tips that have helped me achieve that level of focus. I hope this is helpful to anyone else as it was for me.
1. Have a vision
Even before writing the first characters of code you should know in your head what you want the final product to look like. Doesn’t have to be all the details about the database schema and the methods arguments of every classes. But each classes relationship and role could be a good start. As an example, if I’m building a DVD collection website, it’s trivial to determine every possible field of the dvds database table, but it’s crucial to know my dvds table will be the centre of my app. If you have a clear vision, you’ll be driven by it and nothing and no one will be able to stop you from achieving it.
2. Find a setup and stick with it
Although I don’t think having a routine for everything is something good, you should have some fixed parts in your moving train towards coding nirvana. Determine in your vision what are the innovations and automate or routine everything else. For instance, the way you place the windows on your screen should always be the same when you enter coding mode. And when you stop programming, close all those so you record that having this setup mean you’re coding. This way you won’t be distracted by your Google Reader or Adium window.
4. Drop the mouse
Not using the mouse is the best way to become a very effective programmer. My philosophical reason is that you’re closer to the machine in the way that all you fingers are directly connected to your computer transmitting information as it pops up in your head. Switching from mouse to keyboard is costly, do it as less as possible or only for uncommon tasks.
Using the mouse is good for exploration mode, when you don’t really know what you’re looking for. But since you should have a clear vision of what you wanna do, go with the most direct method of input, the keyboard (until they find a way to connect it right into your brain).
5. Use tests to focus
A common problem with debugging is when you do it with
When debugging with tests you document your assertions in a permanent way. “I wanna make sure this returns ‘stupid puppy’ 46 times”, well don’t
assert_equal "stupid puppy\n" * 46, puppy_output
in a test case.
The next time you’ll have to fix a bug or add a new feature you can focus on making the test pass, not scanning the output. As with the mouse, scanning is for exploration mode.
5. Put headphones on
Listening to music occupied the left part of you brain. An old study presented in the amazing book Peopleware shows that if you listen to music while coding, you will end up with a less creative approach . This might be true, with new music you’re listening to for the first time. My tip is to listen to music you know by heart. The objective is to eliminate any unexpected variant in ambient sound. If you know the music really well, you won’t be surprised by any sound, it will serve as a constant background noise. It’s a great way to focus real fast and cut yourself from the outside world, you know, the real world…
Now what do you do to get in the zone ?
 He and his college made some programming test with people listening to music (own choice “if music” plus type of music in the affirmative) and people that were kept in a silent environment.
It turned out they program equally fast but the people listening to music show less creativity.
Some sub tasks of the test required a length transformation of some data. This was set up so it looked very complicated with a lot of steps. The end result however was that the transformation was very trivial and in come cases you ended up with the data unchanged.
The people listening to music missed this to a very high degree while the programmer working in silence almost uniformly spotted the simple transformation.
The suggested explanation is that the right brain more creative / insight dominated is used for listening to music while the logic left brain is busy coding. Those two task can be done fairly independent but when creativity is needed the right brain is busy so the broader insight into what is being programmed is often missed.
(Summary taken from bstadil, thanks)