Business Insider has a piece explaining “Why programmers work at night.” Swizec Teller, a freelance programmer who lives near me (note to self: interview him for the Rest book). So what’s his explanation? First,
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…. 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…. So they get most of their “work work” done during the night when everyone else is sleeping.
Second, somewhat counterintuitively, fatigue is the programmer’s friend: “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.” This is a virtue not because the work is so absorbing, but because
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.
Finally and most straightforward, “a bright screen keeps you awake.”
The first two explanations are consistent with what other programmers have told me: that you need to keep lots of things in short-term memory when you’re writing code; and at the same time, much of what you’re doing is more like bricklaying than architecture.
Here’s a 2012 talk Teller gave at Webcamp Zagreb, (via YouTube):
He’s also written a book about the subject.