If you're a developer, the kind who doesn't work on a punch clock, chances are you've written code at midnight or even later. Have you ever thought about why that is?

Let's do a thought experiment together. Let's pretend that you're the founder of a new, perfect company. It's not a Silicon Valley style hell-bent-for-leather startup—instead you're funding it with a large inheritance. There's no one telling you how to run your company and no urgency to make it profitable any time soon.

It's a software company so as the founder you're going to hire software developers. You have fun planning the ideal layout of your perfect office space, making sure each developer has the best computer hardware money can buy. You want to set up your developers for success because you know your company will depend on their performance.

In your perfect company scenario, which working hours would you choose for your developers? You recognize that clarity of thinking is paramount for this kind of white-collar work. If your business was digging ditches it wouldn't be so important. You're not a neuroscientist but it's obvious to you that the human body is designed to be alert and awake during daylight hours, and to rest and rejuvenate itself at night. You know from your own personal experience that it's harder to fall asleep when your brain is stimulated.

Given that, and assuming your perfect software developers will work whenever you ask them to, would you ask them to work at midnight?

I'm guessing most people would say "no". If that's the case, then why do you work so late?

Because it Feels Good

Coding feels good. More than just feeling good, it's addictive. Uh oh, "addictive" sounds bad, but it needn't be. There are positive addictions, such as running. Personally I've gained huge benefits from the addiction of coding, including:

  • the satisfaction of creation
  • the thrill of bringing something quickly from conception in the mind to existence in the real world
  • relaxing into the sense of order in the computer world
  • a steady emotional tone when I'm feeling emotionally unsteady
  • feeling like I'm doing something worthwhile with my time
  • a fulfilling career

Why is coding addictive? It's the based on the feeling of accomplishment. This is the same feeling that motivates people to play computer games. The addiction is heightened because of variable rewards—sometimes writing code works when we expect it to and other times it takes longer before we get the dopamine hit.

Awareness = Choice

Knowing that coding feels good and is addictive gives us the power to separate concerns (a concept familiar to most developers). The concerns to separate here are:

  • to write code effectively
  • to feel good

The goal isn't to separate the concerns completely—it's OK to feel good while writing code effectively—but to notice the principal driver of our motivation in any given moment and to make sure it's aligned with our goals. For example, it's a good idea to ask oneself, "Am I coding at midnight in order to write code effectively or am I doing it to feel good?" If the answer is "to feel good" then there's nothing wrong but it creates an opportunity to ask oneself, "What other ways can I satisfy my goal of feeling good at midnight?" There may be better methods of satisfying that goal which don't stimulate the mind as much (making it easier to fall asleep) and lessen the risk of writing code bad code (which can generate more work for you and your coworkers).

When I began my hobby of coding as a teenager I would frequently code well past midnight, sometimes until 3 am. Today I never do because I'm more effective at coding during the day and I've found better ways of making myself feel good at night (such as meditation, watching a TV show, talking with friends, etc.). To help yourself separate the two concerns, ask yourself these questions:

  • When are the best times of day for me to write code effectively?
  • Are there better ways of making myself feel good at night?

This Might Hurt Just a Little

Be prepared for the possibility of negative emotions to arise. One of the reasons we have addictions is to avoid feeling negative emotions. This was a big reason why I spent so much time coding as a teenager. When you ask yourself what else you can do besides coding to make yourself feel good, you may notice emotional resistance to the question arise, as though your mind is saying, "Coding IS the best way to make myself feel good right now. That's why I'm choosing it!" Don't believe your mind right away if it tells you this. It may be true but it's worth taking time for a deeper inquiry to see if it's really true for you or if it's your mind's way of avoiding negative emotions which have been kept at bay by the addiction.

My purpose in writing this article isn't to go deep into psychology, it's to get you over the hump of resistance that you probably aren't even aware is there. Most people don't know that coding is addictive and that when it's part of their job they can slide into workaholism. We don't have many societal cues to question what looks on the surface like a Puritanical work ethic (or the all-consuming startup "ethic"). Until someone else who's gotten over the hump himself points it out, you might never bring your curiosity to it, so that's what I'm doing for you in this article. Once you're over the hump you can reap the benefits of both feeling better and writing code more effectively.