How I Write Code
My approach is usually to stare out the window or at a wall or blankly at my desktop and “see” the code, in a sense. Almost as if projected onto the world - but not quite. I think I’m seeing packets of meaning rather than programming language text. It’s hard to say for certain. I can move those around and make adjustments and sort of “push” sub-designs to the side, connect them up later, etc. and it all feels very visual. A design will often come to “look” good before I even start typing anything related to it.
Occasionally this doesn’t seem to work. I think it’s when the problem isn’t well defined enough to know quite where to start or if the problem involves doing a lot of stuff I haven’t done before. In those situations I usually have to wait out the process and “watch” code trying to come together in my head until some part of me determines that I simply don’t have enough information to continue. When that happens, I sit down and just start typing code out so that it gets out of my head and into the program. Once enough of that is done, even if it’s crap, that seems to clear up the mental clutter and I can go back to my usual approach and refactor later once I know what that original code was really for or where it goes (if anywhere).
This happens without my wanting it to happen, sometimes. I might be driving and suddenly get a flash of something that’s wrong in the code or a way to fix a bug I noticed hours or days ago. I’ve found memory leaks while driving and nowhere near a computer, for example. It can be a problem when trying to go to sleep at night, too, and I found the best way to deal with it is just get up, fix the code, and go back to bed. Trying to stay in bed and ignore it simply leads to insomnia.
June 1st, 2009 at 10:42 am
When I was doing database work, I used to just get comfortable in bed, starting to drift off and that was the exact moment the code that would fix my issue I had spent 12 hours working on would magically appear in my head. I would always have to get up and fix it or risk losing it by morning. I think just being able to step away from a problem and relax a little helps sometimes.
June 2nd, 2009 at 8:37 am
@Xander I’m the same way. All solutions come out just before I hit deeps sleep. Nowadays more ideas are starting to appear or how I can make other applications currently on the web better. I usually take the weekends to do something non-programming related and less complex to get my mind back in order for a fresh Monday. It helps stay creative too.
June 2nd, 2009 at 9:47 am
Sports like running and swimming help me a lot, too, in coding and in solving research problems. While running and looking at the dirt track in front of me and at the trees around me, I focus on the problem/bug/feature and get many more ideas than looking at the screen. While swimming I can only see white tiles, but that helps too.
June 2nd, 2009 at 10:44 am
If you’re talking about”pushing” and “connecting” you might not be a visual thinker, but a “kinesthetic” or physical thinker. Think about it: there may be both physical and visual elements, but which is dominant?
June 2nd, 2009 at 2:42 pm
I’m kinethetic and agree with my anonymous brother. This is exactly the way I work. Muscle memory is a key component of this and kinethetic thinkers tend to work out a problem by putting it together mentally first for practice. It makes sense when you consider that thinking about, visualizing, and concentrating on a task works the brain in the same way as physically performing the task. In this way someone who plays baseball will visualize and concentrate on the motions of swinging the bat while waiting on the bench and then be better prepared to make a hit.
No reason programmers can’t work the same way. ^_^
June 2nd, 2009 at 4:14 pm
Smoke breaks and drinking work for me–I’ve done some of my best work while slightly buzzed believe it or now.
June 2nd, 2009 at 5:25 pm
I’ve come to treat my “subconsciousness” as an asynchronous machine. I submit async requests to it by zoning in on the problem, then putting it away. When my mind produces something in the background later, it sends me the (sub)result in another async message. This machine can be trained by keeping it occupied with requests.