Programmers: You Snooze, You Win


The ultimate fuel of a programmer.

Energy drinks and Coffee.

The best friends of a programmer.

They are always on the programmer’s desk and they never leave programmers alone. They help them in their programming journey. They provide them the ultimate fuel they need to be a better programmer.

Deadline is coming…

You are still behind the scheduled program. You need more time to complete all your tasks. For that, you need to write more and more code. You have to be awake even at nights. You have to sacrifice your sleep for programming. You think if you can find more time, you can do a better job and meet the deadline.

It’s 11.30 PM.

You are a bit sleepy. Your body is telling you to sleep but you have to stay awake. You need your ultimate fuel. Let’s drink coffee. Ohh, you feel much better. Caffeine provided you the 2 more hours you needed.

It’s 1.30 AM.

There are still 10 bugs that you have to fix. Your fuel is being consumed… Let’s drink an energy drink so that you can still keep coding.

It’s 3.00 AM.

You committed your code to source control. You felt relieved. You were productive. You completed all tasks assigned to you. You may also think that other programmers in your team who can see your commit now think that you are a hard worker. You are a great programmer. Even in the late night, you commit code to source control.

It’s 8.00 AM in the morning.

Your teammate reached you over the phone and told you that there are new bugs in the software after your late-night code commit. How can it be possible? There were 10 bugs you needed to deal with. All of them supposed to be fixed. Why are there new ones now? What went wrong? You did everything according to plan. You were just like those programmers in Hollywood movies. Coffee, energy drinks, nights without sleeping…

You did everything right but what went wrong?

Let me tell you what went wrong.

You were captivated by the imaginary programmers showed in the Hollywood movies. You didn’t get enough sleep that you need. You believed in something wrong for your whole programming career: The more hours you are awake, the more code you can write. The more code you write, the more productive you are. Sleep is just a small thing that you can sacrifice to become a hard-working programmer.

But what about your health? What if I told you that what you believe in was essentially a false belief. What if there was another option to be more productive, to be a better programmer? Would you stick to your false belief or would you let me wake you up from your long deep sleep? Wait a second. This is the wrong question. This is not what I defense in that article. Here is the right question:

Are you ready to fall into a deep sleep to be a better programmer?

I have great news for you!

Scientists have discovered a revolutionary new treatment that makes you live longer. It makes you healthier. It enhances your memory. It makes you more productive and more creative. In the end, it makes you a better programmer.

Are you interested?

While it may sound hyperbolic, nothing about this fictitious advertisement would be inaccurate. If it were for a new drug, many people would be disbelieving. Those who were convinced would pay large sums of money for even the smallest dose. Of course, the ad is not describing some miracle new tincture or a cure-all wonder drug, but rather the proven benefits of a full night of sleep.

The evidence supporting these claims has been documented in more than 17,000 well-scrutinized scientific reports to date. As for the prescription cost, well, there isn’t one. It’s free. Yet all too often, we shun the nightly invitation to receive our full dose of this all-natural remedy — with terrible consequences.

Yes, my friend. The right answer was standing in front of you rather it was in your bed. As I said before, sleep enhances your memory. It prepares your brain to learn new things. Experiments show that sleep deprivation affects your learning capability. The less you sleep, the weaker memory you have. After being awake for 16 hours, your brain starts to fail. Therefore you should get 7–8 hours of sleep every day.

What do researches tell about this?

According to researches, your sleep quality and stress level matter far, far more than the languages you use or the practices you follow. Nothing else comes close: not type systems, not TDD, not formal methods, not ANYTHING.

Any academic research about “software improvement” don’t provide clear, certain results. Empirical results are mixed.

Clean Code? Doesn’t help to implement new functionality and to find and solve a bug. There seems to be no immediate benefit of Clean Code in the form of understandability.

Choice of programming language? There is no evidence that it reduces defects that much.

TDD? Results are mixed. It might trade effort for defects or maybe it doesn’t reduce defects at all!

It seems that we somehow can’t study knowledge working. However, there are some things that we know that have obvious, overwhelming impacts on fields of all kinds.

Things such as sleep.

Here are some researches that show the impact of sleep deprivation on developers:

The researchers recruited 45 undergraduates and asked them to tackle a programming task. Among the participants, 23 agreed to stay awake the night before carrying out the task, while 22 slept normally. Here is what they found:

One night of sleep deprivation is detrimental for software developers. In particular, sleep-deprived developers produce software of lower quality.

Another research found that getting less than 7 hours of sleep causes dramatic degradation on all mental tests.

What about overwork? (Remember those sleepless nights that you thought will make you more productive.):

If you do 50 hours of work a week, after 8–10 weeks you’re less productive per week than someone doing 40 hours:

Do you want more evidence? Well, I strongly recommend you to read Why we sleep book. The book has many scientific facts about sleeping.

As a result, no programming language, tool, technique, method matters nearly as much as our own minds. If you want to be a better programmer and if you want to write good code, be human. Be healthy. Nothing else comes close.

Thanks to @hillelogram. He tweeted a thread about programmers and sleeping. This tweet was an inspiration for me to write this article. You can see the tweet thread here.