[This essay has been expanded into a book, you should read it, here]

A chimpanzee brain at the Science Museum London

Image via Wikipedia

A popular saying goes that Programmers are machines that turn caffeine into code.

And sure enough, ask a random programmer when they do their best work and there’s a high chance they will admit to a lot of late nights. Some earlier, some later. A popular trend is to get up at 4am and get some work done before the day’s craziness begins. Others like going to bed at 4am.

At the gist of all this is avoiding distractions. But you could just lock the door, what’s so special about the night?

I think it boils down to three things: the maker’s schedule, the sleepy brain and bright computer screens.

The maker’s schedule

Paul Graham wrote about the maker’s schedule in 2009 – basically that there are two types of schedules in this world (primarily?). The traditional manager’s schedule where your day is cut up into hours and a ten minute distraction costs you, at most, an hour’s worth of time.

Prim clockwork of a wristwatch, watchmaking ex...

Image via Wikipedia

On the other hand you have something PG calls the maker’s schedule – a schedule for those of us who produce stuff. Working on large abstract systems involves fitting the whole thing into your mind – somebody once likened this to constructing a house out of expensive crystal glassand as soon as someone distracts you, it all comes barreling down and shatters into a thousand pieces.

This is why programmers are so annoyed when you distract them.

Because of this huge mental investment, we simply can’t start working until we can expect a couple of hours without being distracted. It’s just not worth constructing the whole model in your head and then having it torn down half an hour later.

In fact, talking to a lot of founders you’ll find out they feel like they simply can’t get any work done during the day. The constant barrage of interruptions, important stuff ™ to tend to and emails to answer simply don’t allow it. So they get most of their “work work” done during the night when everyone else is sleeping.

The sleepy brain

But even programmers should be sleeping at night. We are not some race of super humans. Even programmers feel more alert during the day.

Ballmer's peak

Ballmer’s peak, by XKCD and shame on you if you don’t recognise the style

Why then do we perform our most mentally complex work work when the brain wants to sleep and we do simpler tasks when our brain is at its sharpest and brightest?

Because being tired makes us better coders.

Similar to the ballmer peak, being tired can make us focus better simply because when your brain is tired it has to focus! There isn’t enough left-over brainpower to afford losing concentration.

I seem to get the least work done right after drinking too much tea or having a poorly timed energy drink. Makes me hyperactive and one second I’m checking twitter, the next I’m looking at hacker news and I just seem to be buzzing all over the place..

You’d think I’d work better – so much energy, so much infinite overclocked brainpower. But instead I keep tripping over myself because I can’t focus for more than two seconds at a time.

Conversely, when I’m slightly tired, I just plomp my arse down and code. With a slightly tired brain I can code for hours and hours without even thinking about checking twitter or facebook. It’s like the internet stops existing.

I feel like this holds true for most programmers out there. We have too much brainpower for ~80% of the tasks we work on – face it, writing that one juicy algorithm, requires ten times as much code to produce an environment in which it can run. Even if you’re doing the most advanced machine learning (or something) imaginable, a lot of the work is simply cleaning up the data and presenting results in a lovely manner.

And when your brain isn’t working at full capacity it looks for something to do. Being tired makes you dumb enough that the task at hand is enough.

Bright computer screens

This one is pretty simple. Keep staring at a bright source of light in the evening and your sleep cyclegets delayed. You forget to be tired until 3am. Then you wake up at 11am and when the evening rolls around you simply aren’t tired because hey, you’ve only been up since 11am!

A city

Image via Wikipedia

Given enough iterations this can essentially drag you into a different timezone. What’s more interesting is that it doesn’t seem to keep rolling, once you get into that equilibrium of going to bed between 3am and 4am you tend to stay there.

Or maybe that’s just the alarm clocks doing their thing because society tells us we’re dirty dirty slobs if we have breakfast at 2pm.


To conclude, programmers work at night because it doesn’t impose a time limit on when you have to stop working, which gives you a more relaxed approach, your brain doesn’t keep looking for distractions and a bright screen keeps you awake.

You should sign up by email to receive tips and science about productivity and keeping your sanity as a developer, here.

Enhanced by Zemanta

You should follow me on twitter, here.

Get 10 of my best articles and talks

Leave your email and over the next few weeks I will send you the best material I've written since 2010.

  • Rico

    I used to work “shifted” hours in my younger days programming, usually 10:30 or 11 AM to 8 or 9 at night, sometimes later.  But for my own sanity (and the fact that I now want to talk to normal people on occasion) as well as my current job, I work 9-5:30.  It wasn’t easy. My mind still wants to sleep until 9:30 and be up at 2AM.  But I’m not in my 50’s and sleep is more important. I can’t function on 4 hours of sleep anymore.

  • Guest

    The idea of being “too smart” to do something, so you need to become tired (and in turn “dumbed down”) in order to do it better, strikes me as very odd.

    The problem might indeed be getting distracted and letting other people / things distract you, but that has nothing to do with being too smart. (Why don’t you have to check twitter at night? It’s not like the world stops tweeting when you should be in bed…)

    Getting / being focused is an ability that can be trained and needs to be trained, just like any other.
    Being able to block out the world when you really need to is just as an essential skill as knowing how to use your programming tools efficiently.

  • Agreed! I love coding at night, because at night there is no sense of time, like look outside at 11 AM and then at 4 PM, you’ll notice everything’s changed, the sun is gone somewhere else and birds are returning home, but at 11 PM and 4 AM it’s same, just the same silent, infinite darkness outside.
    I think I made my point, if I write anything more it would look more like a poetry than a comment :p

  • Yes, but I guess almost everyone reading this article has already seen that xkcd :p
    (Still, it should have a link)

  • Consider the possibility of having undiagnosed ADHD. You should be able to focus during the day. If not, get noise cancelling headphones.

  • Anonymous

    I think I can only agree with this. I find that a day of work sitting in front of a computer dulls my senses with the constant influx of email and IM between coworkers, and once the kids are in bed at night, it’s the perfect combination of motivation and tiredness that gets me into the “zone”.

  • Ejoell

    One think everyone seems to be forgetting is that you are not writing code to be writing code.  Your are writing code to meet your customer’s requirements.  Now everyone knows that customer’s requirements are constantly changing, no matter what “safe guards” are in place.  So in order to keep from delivering beautifully written code that has has no relationship to what the customer wants you need that constant interaction with the customer.  A number of the developers for web apps here are not only not in their company’s office, but when they are working from home, they are not available during the day at all.  The customers here on site are so extremely frustrated due to a complete lack of responsiveness to change requests and failure to meet stated requirements, that management is considering not picking up their option when that comes due.  I would not want my bosses to realize that they lost a contract because I was not available to the customer.

  • Confused

    Looks like you need to spend more time learning how to write, judging from the evidence you have supplied.

  • Confused

    I wouldn’t hire you to write code for me. You can’t organise a decent sentence: “The only one I seen do stuff like this is my boss “

  • Pingback: Man borde inte sova när natten faller på… « Skogsrå bloggar()

  • Harald Walker

    I am also one of those 11am to 3am guys. If I don’t force myself to wake up earlier I quickly fall back into such pattern. Working at home helps me to be more producting during regular office hours without many of the typical distractions of an office environment. If you google for morning vs. evening/night people you’ll find some interesting results. Studies have obviously shown that evening people are smarter and more creative, and have a better sense of humor. According to this http://www.inc.com/news/articles/2010/07/research-says-morning-people-are-more-proactive.html article it also evolves over a person’s life cycle: Teenagers are evening types; between the ages of 30 and 50, people are evenly split between morning and evening types; and people become morning types as they pass through their fifties.

  • Pingback: Shorts of Sorts: Article 1: Brain Plasticity « Revelations in Art()

  • Guest

    Or you could find other things to do besides riding someone for their typos.

  • Jwkim5050

    Well, be your own boss and tell’em leave the message after the beep while you are sleeping!

  • Minhajulshaoun

    I was frustrated as i tried to live like a normal person…, who works at day and sleep at night. I forced myself to sleep at night when there is no work pressure. But when there is pressure, if find myself reversed automatically. Your nice article explain everything.


  • Alfonso J. Ramos

    Hi, I want to expand a bit from my experience.

    One of the reasons to do not lock oneself up is because of unexpected noise. Be it music, the tv, people chatting, whatever, if it is unexpected it drags attention. One way to mitigate this is to wear some headsets and listen to well known music. What kind of music? Music without lyrics or with lyrics you know by memory, and of the type of music wont make you stand up and dance, both classic and rock works for me. Still it doesn’t replace the night but that is what I do when I get to “i-didn’t-do-shit-panic-mode” @google-b67913b0148ffcb3e9bfd35179a786bc:disqus mentions, when that happens I need the day to catch up [I wonder if that did ever happen to him]. Interestly enought part of my brainpower goes to the music, that makes sure I have no idle-thinking around taking me to check mail or something. A fast computer is vital here, if your machine is slow you start to have idle-thinking wandering around… in those “wait” moments (for example when the computer is loading something, or whatever) I can just listen to the music and be with it, I will get back to work faster that if for example I went to check mail.

    It is not about being sleepy, it is about being in the present. If you have time to expend your brain start thinking about what happened or what you will do letter, of somebody sended you a message or not, and so on. You need to get back to the present. At night you are not sleepy because you have tweaked your day like that, still it is correct it is about efficient use of brainpower, it happens just because you learned to do not put it somewhere else… there learning is where beings sleepy helps, the first days you were sleepy and that made you focus (because you had to) and you learned to think that way, later on you are no longer sleepy because you adapted youself and you are still efficient because that’s a new habit you learned.

    In fact, when you are sleepy you learn better, somehow you get in contact with your subconscious mind and that’s excelent to pay attention… but not too much to react, you are sleepy anyway… you are listening, but hey! you are sleepy… so being sleepy is not good to make things, but it is to learn.

    Yes, the awake-sleep cycle seems to get an equilibrium around 3am – 4am, it last for months, but gets disbalanced sometimes. Sometimes intentionally becuase you got to be present at xyz presentation, meeting or something. Sometimes it just happens, it will drif towards going to sleep at 6am, and after that you rather stay up one day without sleep get it right again or you will end up going to sleep at 2pm.

    Lastly, I don’t drink coffee, you’ll see, cooking recipes are algorithms. Once you make the connection and with a little research you will make your own energetic cocktails that are cheaper that those energy drinks from the store. I don’t like going out to buy those at midnight [yes, procrastination makes it’s dent anyway], also (until recently) there were no close big makets to buy those, so it was natural for me to “craft” something.

    Please add link to xkcd.

  • Bishop

    Agreed.  I need to send more money to David Cretu (Only for MCMXC; the rest pale by any comparison) and The Offspring for their unwitting assistance in grinding out some of the best code I’ve ever written.

    I’m finding I also like to be warm when I’m coding, but chilly when I’m break-fixing.  Maybe related to sleepy-brain and awake-brain. 

  • One of the best article to describe a freelancer like me and im proud of this 

  • Nice article. Interesting. Consoles me that I am actually not a dirty slob!!! 🙂

  • I consider myself as working “nights”… When I was growing up my father was a steelworker and he worked shifts.. one of his shifts was 9pm-6am.  This is my favorite shift to work and always has been.  I sleep from 7am-1pm usually sometimes I sleeep a little longer.  But consider this, 9pm-6am the phone isnt ringing, the dog doesn’t want to go for a walk, your kid doesn’t want to be fed or get a diaper change, your wife doesn’t want you to run get milk, nobody is knocking on your door..  This is the best time to work.  I keep the lights on in the room because a dark room and a bright computer screen makes for sore eyes.  Keep the room bright if you want to work best.

  • Anonymous

    Stunning insight. I really enjoyed how you analysed this excellent post and provided rational reasoning to back up your thinking and prove that your answer was in fact a more complete and in-depth look at the situation. If you’d just made some flippant remark about the author being delusional, followed by some quip about your own habits, well… I guess you’d have come across as a real jackass.
    Good thing THAT didn’t happen!

  • Guest

    This job, as well as my last, is a mid-size company with a open-air environment.  You can get up and leave to run errands, pick up your kids, go to their plays/games/etc. with as little as an email (if that) telling anyone who MAY be looking for you that you have to run.  As long as you’re getting your work done on time, it’s never an issue.  Work-life balance is something I make sure to ask about during an interview, so my feelings aren’t hurt when I need to leave early or when I choose to show up at noon and stay til 3am.

  • Ousmane Ba

    I like to call system time because I usually do more than programming. One of the things I can point to is efficiency
    there are no lulls or posing or  I would like to say “day” dream if hat occurs you just go to bed.

  • unkmar

     Sometimes the focus or anti-focus of music allows me to just punch out the code that is already swimming in my head.  When I say swimming, the code is almost fixed in form.  Variable names and some structure may bounce around several times while finalizing into digital form on screen. Other times I need to relax, have lunch or something away from the screen and keyboard.

    And/or the music becomes a distraction because I’m trying to work out a grueling detail.  At those times the simpliest of things can put me on edge.  Long sleeves, a watch keeps twisting, rings on my fingers while I’m trying to type, just a little chilly in the room.  Granted, I don’t have to be perfectly comfortable.  There are just a few things that can push me just enough out of comfort to break my, now, intense concentration on the problem.Working on bits of code that you already have formed is easy.  Working on the large problem and reworking the code takes a measure of planning and is generally slower and more difficult in any tangible form such as a paper, notepad, dry board.  The brain is simply faster, and a simple distraction and tear it down like a gentle breeze destroys a house of cards.  Sometimes I will make skeletal ideas of the program.  A generalized workflow of how it will work.  A higher level program that calls all sorts of routines that simply don’t exist yet.  Then build the guts into place.

  • Possumking

    wasn’t “reduce in distractions” the first reason in the article, and then kind of the second reason also?

    . . .

    This article could be pretty great, if it were true, but it’s not (and it’s stupid). The REAL reasons programmers work at night are:
    it doesn’t impose a time limit on when you have to stop working, which gives you a more relaxed approach, your brain doesn’t keep looking for distractions and a bright screen keeps you awake. 

  • Bogdan Dumitru

    I found out that I was most productive living in totally different timezone. For a few weeks the only way I could get to Uni and get some work done for other stuff was to go to bed at around 5PM and wake up at 1-2AM. I would then start the day off with some breakfast and tea then get to work … at 10-11AM I would probably head off to school, depending on what I had going on. Then at around 3PM I’d be back home eat watch a soap then sleep :). It was a fun experiment and I think my daylight / darkness ratio wasn’t really affected.

  • Wake up in 4-5 am and you will have all the peace you need.

  • The comment is true. Only douchebag here is you

  • Have you ever been reading a book and found your mind wandering? Or watching a slow movie and your mind wanders? Or even listened to somebody speaking very slowly?

    Your mind starts wandering and losing focus because it’s got too much bandwidth for thinking and what you’re doing simply isn’t filling it up. But when you lose too much focus you can’t do the task anyway, so might as well narrow down the bandwidth a bit for a net positive.

  • Only one thing is missing: at night all the noises of the day, all the noises we are barely aware, simply fades away. And a better silence, that silence in the night, is what we really need to concentrate.

  • There is something about mental activity when you are sleepy. I remember a book by a mother who raised a child genius in which she says her son remembered the most of what he studied just before bed or when he was sleepy

    I find that what I study in the middle of distractions doesn’t need to be revised as all the distractions around me stop my brain from galloping around and only allows me to move inch by inch through the material. On the other hand when I’m free from distractions I usually find myself missing a few points in between  or has trouble recollecting some because I tend to skim over a lot of fine points.

    But,  Its twice as hard to study with all the distractions around.

  • working night is more relaxing, co’z you can sleep ahead when you get tired 😛

  • Guest

    Of course I have experienced that. I believe everyone does from time to time.
    But that doesn’t mean I had excess bandwidth to waste.
    It means whatever my mind wanders to is more interesting / important at that time.
    Maybe an unsolved problem or something that I really liked or hated.
    It’s just another form of distraction; not seeing that, which I got distracted from, as important enough to stick with it.

    If we really couldn’t perform “low bandwidth” tasks effectively at the height of our mental abilities driving a car or reading a novel would become impossible unless we’re at the brink of falling asleep.

    Don’t get me wrong, external influences are important and having the right environment helps tremendously. But I doubt getting tired does. (There are studies showing that tiring reduces attention and coordination, while increasing mistakes, stress and accidents and that those effects increase exponentially rather than linearly.)
    I agree with your observations, just not with your attempt to explain them.

    I believe the tranquility of night (slightly) outweighs the disadvantage of staying awake for long hours.
    If you can manage to shift your whole day cycle you might actually get the best of both worlds, but I’m afraid most of us cannot afford to isolate themselves that much from co-workers, customers and the rest of the world…

  • Anonymous

    Speaking of programmers, hope you know that your RSS, Atom, and pingback are not working, giving error 500

  • I do know. The traffic has mostly melted the server these past two days so only this page, which is static, works. The links that cannot be made static (like rss) throw an error.

    But if you use the “Subscribe in a reader” link at the bottom of the post, that still works. http://feeds.feedburner.com/AGeekWithAHat2

  • Diego Schulz

    Maybe for some people. I know nothing about the pressure of deadlines or about satisfying a whimsical pointy-haired boss. I code for fun, yet the article describes perfectly my case. 

    Saludos viejo! 

  • Philou

    Mabe having all your surrounding sleeping when you code gives more room to your own thinking processes.

  • dev

    For me it’s also the pressure in the evening, that the whole day didn’t happen much… so in the evening the day is soon finished, and there have to be some results for being a good day!

  • Avihu Turzion

    I think Cliff from cheers put the basic phenomena best in this quote: http://blog.pilnick.com/post/66268775/well-you-see-norm-its-like-this-a-herd-of

  • Good read 🙂

  • Rich

    I’ve noticed that when I’m very tired I’m better at playing computer games that requires fast action. My brain seems to go into some kind of auto pilot mode where it just reacts instinctively instead of thinking to much of what it’s doing.

  • Kraphas3

    he doesn’t need to be Shakespeare to write code. 

  • Just briliant!

  • Stefy1995

    YES! you are so right!

  • Gud one dude, but even DBAs work in Night shift and hold many of them true for us also. 😉

  • This literally describes me from the last 6 months.  I was living in a different personal time zone.

  • Wickedproxy

    I am not a “coder”, but I am writing a sifi book. I do the same thing. I think about the the story as a whole and how I want it to go. Then I start to fill in the gaps and add detail to the story. An interruption brings this to a screeching halt that I usually don’t recover from that night. Doing this is nearly impossible for me during the day.  

  • Sssssmokey

    It’s not true for me, I don’t have time limits at the moment.  I just enjoy writing lots of code that I hope will eventually make me money.  They are all my own personal projects however, no one would care if I never finished them at all (at the moment).

    So maybe you and the other guy just need to get your shit together?

  • Sssssmokey

    Haha read your reply RIGHT after I posted mine.   There are programmers and people who write code for a living,  I suppose.

  • Sssssmokey