Recently a good friend of mine and fellow programmer talked about his experiences with ‘programming on autopilot’, as he described it to me and other friends in an email:
[…] Sometimes I realize it’s happening as it is happening. It’s like I see myself in some sort of a dream. I’m not aware of any particular part of my mind that is thinking about programming. It’s like I am mindlessly cutting and pasting things out of my subconscious. I look at my screen and my eyes cross. I don’t even know what I’m doing. I don’t really know what the words say, but everything compiles, and everything works. […]
If I ever go back and carefully inspect things with my brain turned on, everything looks okay. Things are documented. Resources aren’t wasted. Functions are cohesive.
He asked if the experience was familiar to any of us and if we thought it was good or bad. So I felt like sharing my response, pasted below.
It sounds familiar. I feel like I once wrote code with that kind of mentality, although by its very nature it is not easy to exactly say, “Oh yeah I did that.” But I am still sure I zoned out during programming at some point.
Nowadays I tend to take the opposite approach when programming. I try to maintain an acute awareness about what I am doing at all times, to the exclusion of my environment, e.g. I won’t answer my phone or even the door in the middle of writing a function. I feel like nowadays I program more slowly because I spend a lot of time methodically planning out what I intend to do. Like I will periodically just read my code; not looking for bugs or anything, just reading it in my head, both to stay focused on it and also to ‘listen’ for anything that sounds awkward, maybe a function name that sounds too general, or a variable name, or anything else. A lot of my programming time is also spent consciously deleting code, throwing away everything I can until I have only what is essential.
I think both approaches have pros and cons, and I do not believe either is superior to the other. For example, one con to my approach is that I feel mentally fatigued rather easily. I never write code without listening to music (unless it’s under some extraordinary circumstances) and that acts as a tether to the rest of the world, so that at least some part of my brain isn’t thinking about the code that every other part is focusing on. I get physically fatigued more easily nowadays anyways, and trying to maintain an incredibly narrow mental focus on code for long stretches of time certainly doesn’t help.
I’ve naturally fallen into that routine, so maybe that is just what works best for me right now. I’ve heard about all kinds of different ways to approach programming, and I don’t believe there is any one methodology that suits everyone. I suspect that over time we all naturally adopt the approach that is best in accord with our capabilities.