Thursday 22 November 2012

How to Focus on Programming

In order to become a master of programming one needs knowledge and the ability to focus while putting that knowledge into practice.  I will begin this blog by teaching you how to focus, and then move onto knowledge.

Focusing your entire consciousness on what you're doing is essential for any job that requires intelligence.  Not only does focusing give you the ability to be more productive, but it also helps you enjoy your job and reduces stress.

In order to learn how to improve my concentration,  I looked for books on the subject.  It seems that most books on concentration come from Eastern religions and are more about meditating than learning to focus at work.  I was looking for something a bit more scientific.  I read a book called, "Can I Have Your Attention?: How to Think Fast, Find Your Focus, and Sharpen Your Concentration."  Unfortunately the book seemed to be more for martial artists, and other people who need to think quickly, rather than those who need to solve complex problems.

Having read a number of books on thinking and the mind, and having fourteen years of experience as a professional programmer, I think that I can share some good advice.  Hopefully reading this will be more efficient than trying to find a good book on concentration and reading it.


Your sub-conscious makes you think about things by noticing related things in your field of vision.

Pause for a moment, and think about that heading.

Imagine you're in a pitch black room, and cannot see anything at all, except for your keyboard, mouse and computer screen.  Your computer has no wallpaper and no icons.  The only thing you see is your IDE.  This is the ideal environment for focusing on programming.  Your mind has absolutely nothing visual to focus on, except for your work.

Of course it's not always practical.  If I minimize my browser, this is what my desktop looks like right now:


My wallpaper is a pretty picture of the head office of the company I work for.  No, I don't have to have this wallpaper.  I simply put it there to generate a good feeling about the company, encouraging my sub-conscious mind to enjoy and focus on work.

I have loads of programs, but I don't need to see icons for every one of them.  I have only five icons on my desktop, but I never use any of them.  One of the icons is for a tool that I wrote specifically to do my most common work tasks.  I don't use the icon, because I've created a keyboard short-cut for it, which is quicker and easier.

Here are some ways to remove visual distractions, both conscious and subconscious:

- Clean your desk, removing everything that doesn't need to be there.
- Clean your desktop, moving all your icons into a folder, so that your desktop is empty.
- Use a wallpaper that encourages you to do well, or at least doesn't encourage you to think about anything else.

Remove audio distractions

Some people like to write code while listening to music.  If that works for you, then great.  My work environment is quiet enough, I can get into the zone without any problems, but at home I close the door and wear ear plugs.  Technically they're attenuators, also known as musicians earplugs.  I had them custom made to fit my ears, and they cut out most of the noise around me.  Not all though, as they're really meant to limit loud noises, rather than eliminate all audio.

Remove internal dialogue distractions

I find the most difficult time to concentrate is after I've had a controversial discussion.  My mind seems to get excited and not want to think about anything else.  This is why the best time to program is after sleeping, when your mind is empty.  Here are some suggestions:

- Never do anything too interesting before work or during your lunch break.
- Don't check your Facebook / personal email during work time.

I suppose I could summarize the above by saying that up until you leave work you should have a very dull existence... this will allow you to enjoy your programming more, while not thinking about anything that could be more interesting.

Remove excitement and anticipation distractions

One's mind seems to work in a relative sort of way, meaning that the more excitement you have in your life, the less exciting programming will be, and the less excitement you have in your life, the more exciting programming will be.

If you have to do something which is mentally exciting then you need to separate it from programming.  Do it somewhere completely unrelated to work, and at specific times which are not near to programming time, and especially not before programming.

- Don't use your work computer or environment for anything which is too exciting.  Your mind will relate your computer / environment to that activity, and try to get you to do that instead.
- If there's something your mind keeps thinking about instead of what you want to focus on, learn how to make decisions and decide not to think about that at all, or try and understand why you're thinking about it, and remove the cause.

Remove physical distractions

- Get enough regular sleep (seven and a half to eight hours).
- If you're tired, lie down for ten to twenty minutes.  It doesn't matter if you fall asleep or not - the break will help.
- Eat if you're hungry, but...
- Don't eat a big lunch unless you're planning to have a nap afterwards.  Work out how much you can eat without feeling tired.

Remove interruptions

A tiny interruption could send your mind down a different path, costing you minutes of development time.

- Switch off any real time messengers, like Skype.
- Close Outlook
- Unsubscribe to any emails you don't need.
- If you have a fancy email client, use it to write rules to automatically recycle emails which aren't important.
- Switch off your phone

(Basically switch off anything that could interrupt you.)

Set specific times of the day to read your work email, for example, every three hours.  Read all your emails, respond to all of them, and then close your email client.

Be healthy

I've always been pretty healthy, so I don't have much experience with this, but these are the things that experts always say, so here I'm just writing down whatever sounds right :)

- Get regular exercise (something like jogging)
- Eat less sugar (reducing the amount of sugar you eat actually makes things taste sweeter)
- Eat a high fibre breakfast
- Don't smoke, take drugs, or do anything that is addictive and could distract you from your work
- Don't drink coffee - rather get enough sleep
- Don't drink too much alchohol

Focus@will

There's a website at https://www.focusatwill.com (and no, they didn't pay me to mention them).  They have some music that you can listen to which is supposed to help you focus.  You specify the amount of time to play for, which is a neat way of specifying how long you intend to focus for.  I like using the ambient music on their site to focus.  In other words it does actually work for me.  Whether or not it will work for you, I don't know... no harm in trying.

As always, any thoughts?  Agree?  Disagree?  Questions?  Let me know :)


Images:

1. Courtesy of Maggie Smith at FreeDigitalPhotos.net
2. Courtesy of imagerymajestic at FreeDigitalPhotos.net


How to reduce complexity and know everything.

Quality We have a great QA. His code is like a Rolex. You look at his gherkin, and smile.  It says what it's testing, in plain English, ...