share
Stack OverflowWays to prepare your mind before coding?
[+80] [32] kmilo
[2008-09-26 17:23:05]
[ self-improvement productivity ]
[ http://stackoverflow.com/questions/140774] [DELETED]

Coding is a very attention consuming exercise, how do you prepare yourself to begin a good coding session?

I use to be more calm and ready to think in a useful way after reading some insightful new posts from my rss reader.

[+141] [2008-09-26 17:28:29] OregonGhost [ACCEPTED]

I refer to the following citation, which is hanging on my office wall at work:

Mostly, when you see programmers, they aren't doing anything. One of the attractive things about programmers is that you cannot tell whether or not they are working simply by looking at them. Very often they're sitting there seemingly drinking coffee and gossiping, or just staring into space. What the programmer is trying to do is get a handle on all the individual and unrelated ideas that are scampering around in his head. (Charles M Strauss)

Actually, I don't prepare for coding. Have a good breakfast in the morning, some coffee, begin the day with browsing my favorite websites and then start coding, maybe with some music, maybe with some audiobook, maybe calm, and don't trick yourself into believing you must be coding without a break. Take the time you need, relax, and don't forget that ten seconds of thinking can save you ten hours of bugfixing.


(32) It's very hard to suppress the feeling that you should be hacking away code. But having a clear mind is #1 priority while coding. Very good answer! - Tigraine
(1) very will written and good qoute. - The real napster
(6) Watch an episode or two of "The Big Bang Theory" before starting. - Secko
I watch television series only in the evening, not in the morning. I might have a look at this though, when I find it in the TV program accidentally. Watching something like that before starting to code makes me want to watch more, rather than wanting to start writing code... - OregonGhost
I personally relate to that in a more negative sense by feeling like I have genuine focus problems, yet encounter short bursts of productivity just enough to keep afloat. - f100
@frou: I also have focus problems when I'm tired and my current task isn't much fun. Luckily it works fine most of the time if only one of the conditions is true, and I typically have some influence on both :) - OregonGhost
(1) Nice quote - stealing it! :) - Vivin Paliath
1
[+22] [2008-09-26 17:47:49] loudej

First, if you expect to accomplish anything significant make sure you can have the next several hours potentially uninterrupted. There's nothing more destructive to a productive mind frame than getting up every twenty minutes to take out the garbage, grab lunch, answer the phone, drive to the pharmacy, etc. Getting your tea, coffee, music, and snack prepared before you start is a good idea so you don't interrupt yourself.

Second, select the task you fear the most and plan to do that one next. I've found if I put off items which seem difficult on the surface it negatively affects my mindset. They can seem to grow into a dark cloud on the horizon, but if you address them early you can turn a mountain into a molehill. Sketch out some ideas for that task on a pad, make a short list any todo bullets which can be individually crossed off, and jump on the keyboard with the simplest possible assumptions. Having a micro-plan and a sense of incremental progress always helps avoid engineering despair.


As someone who keeps my office at home, and has a wife who does the same, I can definitely say cutting down on distractions is number 1 priority for every day. - Eli
@Eli: A programmer? With a wife? - M28
@M28: Haven't you heard? Programmers are like Surgeons 2.0 nowadays. xD - Alix Axel
"Select the task you fear the most and plan to do that one next". Good advice for every human endeavor, not just programming. - Dour High Arch
2
[+18] [2008-09-26 18:33:45] Paul Stephenson

If I really want to get something done:

  • Close down email.
  • Close down web browsers, especially the one permanently on the stackoverflow home page.
  • Close down any application that moves on screen by itself (animated images or auto-refreshing stats, say).
  • Clear my physical desktop: remove the piles of papers that have been accumulating for the last few months.
  • Take a deep breath.

The aim is to remove clutter and possible sources of distractions.

If I really, really want to get something done, also:

  • Email my colleagues asking them not to disturb me (before shutting down the app!).
  • Put my phone on Do Not Disturb.

Luckily my (open plan) office is fairly quiet, otherwise I'd have to consider noise-reducing headphones too.


3
[+12] [2008-09-26 18:11:49] Ólafur Waage

For me i read code, that is either very sad and/or beneficial because when i read code i get ideas and think of what i have done and how to better myself the next time i code.

When i do that and start coding, i have a mindset of bettering myself each time.


(4) that sounds interesting and quite smart. I should try this one. - dr. evil
4
[+10] [2008-09-26 17:25:38] jop

I listen to music. Classical guitars.


5
[+9] [2008-09-26 17:37:56] MattW.

Exercise helps tremendously.


6
[+8] [2008-10-02 12:13:05] Unsliced

Prepare for the next session but ending the previous one properly. Note things down that you still need to work one, targets for the next session, tests you need to write, liberal use of TODO messages in your code.

If you have a decent ideas of where to go with the next day's work before you start, that will make you more productive. If the first 10-15 minutes is completing some tasks and doing good - not rooting around and picking up the pieces - you'll feel better and more confident and less in need of distraction and a reset.


7
[+6] [2008-10-02 12:09:02] pookleblinky

I usually start a programming session with a fresh pack of cigarettes,empty ashtray, a full pot of coffee in a carafe on my desk. I make sure my playlist is all mapped out (no surprising Rob Zombie suddenly popping out of the midst of Paganini, or vice versa), and clear at least two workspaces of all clutter.

Right before coding, I write a little summary of what exactly I'm trying to do, so I don't wander off and spend valuable time working on tangents (despite what I'd like to think, unlike Stallman my tangents are unlikely to ever become Necessary Tools).

If I still get code-block, I find it unusually helpful to go to pastecode and play around cleaning up code I find there. You're guaranteed to find a couple snippets of horrid code that, with a few clickety-clacks, will boost your confidence and ease you into the right mindset.


8
[+6] [2008-09-26 17:27:03] Matthew Rapati

Cup of tea.


9
[+4] [2008-09-26 18:08:37] slim

By designing.

If you write a line of code before your design is more or less clear to you - be it just in your head, in scrappy notes, whiteboard UML, Visio UML, or a big-ass design document - then it's likely to be worse code for it.

If you know what you're going to code before you code it, the rest should be easy.


10
[+3] [2008-09-26 17:53:27] Matt Pascoe

I honestly try to start and end my day trying to take care of any distractions that may get in the way of coding. Like in the morning before I start, I take care of all my emails, quick browse through my daily sites, ask any nagging questions about the code I had from the day before, etc. My morning things can usually be taken care of in a half hour to an hour. At night when I get done I try to take care of the larger distraction, larger being they take more time. One distraction I have is TV shows that I can watch on the Internet, so at night I watch them. This way I am not tempted to watch them while working.

Once you get rid of the distractions get a pop or coffee, a bag of chips or candy, put the tunes on, and start rolling out the code.


bag of chips? ffs.. - Click Upvote
11
[+3] [2008-09-26 17:27:56] unexist

I normally don't need any preparation at all. It's even hard for me to rest if I am implementing something and want to get it done.


12
[+3] [2008-10-02 12:15:24] leppie

Personally, I try to completely visualize the problem and the solution in my head. Then once I am satisfied, I will write the code once, and correctly.


13
[+3] [2009-04-24 17:22:28] Robert Gowland

I start by making a check-list of specific changes I am going to make during that coding session, then check them off as I complete them.


14
[+2] [2010-04-22 01:03:48] Chris J

Getting a good night's sleep I think is paramount for me. I know that if I am running low on sleep my coding abilities start to drop off quite quickly let alone my ability to effectively communicate with my team.


15
[+2] [2010-08-09 17:12:32] TechNeilogy

One good first step is to accept the fact that six months from now, you're more likely to look back at the code you're about to write today and consider it absolute tripe than you are to consider it a work of genius. For some odd reason, the acceptance of this grim calculus makes it more likely that you will indeed produce something worthwile rather than tripe. It has to do, I think, with not forcing permanence and perfection on things. The best code is that which functions as a future stepping stone to the next code. Let the tool do the work; stop the internal dialog and listen to the code, it will tell you what it wants to become.


16
[+2] [2008-09-26 17:27:59] Bob Cross

Peace and quiet - I have been known to put on my over-the-ear headphones at work and forget to turn the music on. Even when I remember to hit play, the headphone wire also serves as a leash reminding me not to be distracted, jump up to make a vending machine run, look through my books for that one reference to that obscure thing from my ancient past....

Basically, find a way to put the distractions away.


17
[+2] [2008-09-26 17:28:04] GEOCHET

Bose noise cancelling headphones [1] and Pandora [2].

[1] http://www.bose.com/controller?event=view%5Fproduct%5Fpage%5Fevent&product=qc2%5Fheadphones%5Findex
[2] http://www.pandora.com/

(2) Too bad that Pandora doesn't work outside of U.S. - unexist
It does if you fake your area code (90210) - Ross Anderson
(1) I don't see why this warrants a downvote. I have a good pair of Bose headphones (not noise-cancelling, though) and have created quite a wonderful Symphonic Metal station for myself. It, in conjunction with a little motivation, does wonders for productivity. +1 - Mike
@Mike: Don't take it personally, I don't. I get lots of serial down votes, they have nothing to do with the content of my posts. - GEOCHET
(6) @RichB: You also seem to do some serial downvoting yourself... - Tim
18
[+2] [2008-09-26 17:58:03] Maitus

Envision the green bar! You gotta love seeing that green bar, right?

That gets me excited to write my first test case, and tests should be written before code, right?


19
[+2] [2008-09-26 17:25:38] Wes P

I find listening to remixed video game music a good way to slip me into the programming mind set. http://ocremix.org/


(1) Game music is great because it usually doesn't have lyrics (less distraction) and is often very rhythmic... I listen to game music all day when I'm coding. - Keithius
20
[+1] [2008-09-26 17:25:21] Brian Knoblauch

I don't code well when calm. Downing a Code Red or 2 gets me going so I can code.


21
[+1] [2008-09-26 18:36:24] catfood

A little bit of internal conversation can help.

  • How am I feeling right now?
  • Is that okay?
  • Is there anything I need for comfort or concentration?

22
[+1] [2008-09-26 17:28:24] Turnkey

Review the "big picture" on what you are getting ready to code, for example the user story or the use case. It helps refresh the mind on the overall task before getting lost in the nitty-gritty details.


23
[+1] [2010-04-22 00:41:25] smessing

Really loud music. I do not mean deafening, but enough to block out all other noise. I find that my brain is really good at blocking one source of distraction, but the problem is when there are too many sources to keep track of. Over-ear headphones turned up a significant amount is most successful for this. I find that after a while of focusing (and this isn't just for programming, but general writing, reading, etc.) I no longer hear the music at all.


24
[+1] [2010-08-08 16:20:20] ZXX

Staring into space is always good - especially when some other ppl are so intent of figuring out what are you doing and it's none of their actual bus :-))))


25
[0] [2010-08-12 12:11:34] chiccodoro

I recently discovered that playing a match or two of table football with my colleagues can help a whole lot, as a preparation before as well as a break between two programming sessions. (Fortunately my current customer has one next to my office!) Its simple: Some physical exercise, something that focuses your mind and trains your eyes and brain. At the same time it helps get your head clear of all the mails, RSS feeds and stackoverflow posts you just read.

Another thing I've discovered: Don't read and answer your mails at the start of the day, but immediately dive into a programming task, because by reading mails you just postpone (and increase) your troubles to get into your stuff.


26
[0] [2010-05-01 14:19:53] Nils

I think it's really important to understand what you are doing. If you have to implement a complex algorithm and you have an idea of how it works, but don't understand how it exactly works then you should not start coding. Instead writing down the problem do some drawings if it can be visualized. (or transformed into a geometrical problem) Go through on or two steps on paper, then figure out how the problem can be mapped to classes and methods and once you understand everything start coding. Eventually some more questions will arise when coding and, depending on the complexity of the problem, you will eventually have to rethink some of your initial toughest; for example changes on the OPP-Model or clear up somethings about how the program should behave in certain situations.


27
[0] [2010-07-11 16:09:02] Rodrigo

For me it's easy as this:

  • Get your cats away or on your lap
  • Get your wife far way or turn on the TV into some soap opera/love movie so they can be hypnotized for a couple hours at least (you can also download more movies in order to extend the hypnotizing time)
  • Get a jar of coffee and place it somewhere you can get without getting out of chair
  • Full ear headphones
  • Lots of heavy metal
  • Write down annoying clients phone numbers, if they call, you pleasantly ignore.

28
[0] [2010-07-14 20:54:44] Dave

I learned from Tom Edison. When he had a knotty problem, he would go over all of the aspects of the problem and then take a nap. He had a bed in his office for this reason.
When I run into a nasty I will dig into it for the information and then drop it for a while.
The answers will come when you finally have enough information.


Edison stole all "his" inventions from Tesla and others. =\ - Alix Axel
29
[0] [2009-04-24 18:08:44] aron

I think it's really valuable to have an itch. I guess many of those who read here knows that feeling. When a thought is firmly planted in your mind's front porch. Even common every day situations seems to be valuable input to your thought process. Taking a shower, going to the store etc. How to make it start itching... brainwashing helps me. =) Something else that I've discovered can be severly disrupting is annoyances in the private life like having an argument with one of your loved ones or the like. It really sucks mental resources from you in a devious way. Try to clear such stuff out of your mind if you can.


30
[0] [2008-09-26 17:38:12] Pete Karl II

The quick, short answer: if you think like a coder/programmer, you'll be more likely to succeed as one

The longer answer: Have you heard of 'Blink' by Malcolm Gladwell? He brings up an experiment in that book that's relevant here.

It involves the subconscious attention we pay to information we're interacting with, and the effect it has on how we act.

In his example, there were a series of students divided into two sets. One set took a test that consisted first of profile questions (age, height, etc.), followed by math questions.

The 2nd set of students had a similar test, except their profile questions included queries about race and gender. According to the analysis, these questions subconsciously reinforced stereotypes about test performance and intelligence, causing the test results to sway noticeably lower than the first group.

This may not have been an answer so much as a pleasant and mildly relevant anecdote from a book about thinking. :D


en.wikipedia.org/wiki/Blink_(book) it actually looks like a very interesting read, might buy it :-) - Nippysaurus
31
[0] [2008-09-26 17:40:12] Gustavo Carreno

I'll start with a good read on my RSS reader and then just phase me into the challenges.

Most of the times I just have to spend a little time looking at the wall to think of how I can turn a boring task into a challenge, and there I go.

Most often anything just trickles my "interest buds" and I just have to spill it out.

And the last thing: Radio, streamed or air waves. I have to listen to Radio. The music keeps me focused and it will help me do breaks, like when the DJ talks about something interesting. Otherwise I'll be distracted by the Radio being silent, since ambient noise really does not affect me on a conscientious level.


32