Programmers and sleep

Programmers and sleep

For most programmers, sleep is an afterthought. It gets in the way of coding. Of inspiration. Of progress. But sleep is an important part of your mental and physical health and is essential in keeping your body running smoothly.

Most programmers I know have some trouble sleeping, a disorder or otherwise. It stems from our obsessive nature and our drive to always be productive. We have to always be doing something. We have to finish that one last unit test. We have to finish that one last level in the new video game.*

Although it can be fun and can have a semblance of productivity, it's usually not effective, especially after doing it for a few days in a row.

We're not robots

No matter what we tell ourselves, we can't work effectively on little sleep. There have been numerous studies done on the effects of sleep deprivation on decision making, and a number of catastrophes have been attributed to lack of sleep, most alarmingly the Chernobyl disaster and the Challenger Accident. The National Center for Biotechnology Information published a manuscript reviewing the "role of human sleep and brain clocks (time-of-day variation in physiology and alertness) in the occurrence of medical and human error catastrophes". They found that sleep deprivation played a key role in the Challenger Accident:

...the recent report of the Presidential Commission on the Space Shuttle Challenger Accident did cite the contribution of human error and poor judgement related to sleep loss and shiftwork during the early morning hours. ... Certain key managers had obtained <2 h sleep the night before and had been on duty since 1:00 a.m. that morning. The report noted that "time pressure, particularly that caused by launch scrubs and turnarounds, increased the potential for sleep loss and judgment errors" and that working "excessive hours, while admirable, raises serious questions when it jeopardizes job performance, particularly when critical management decisions are at stake".

The Journal of Experimental Physchology: Applied backs this up in their article The impact of sleep deprivation on decision making: A review:

It is perhaps just a coincidence that some of the most renowned man-made disasters or near disasters concerning nuclear power plants, such as Chernobyl, Three Mile Island, Davis-Beese (Ohio), and Rancho Seco (Sacramento), all occurred in the early morning and involved human error in failing to contain otherwise controllable but unexpected and unusual mechanical or control room malfunctions. With all four, experienced control room managers misdiagnosed and failed to appreciate the extent of the fault and then embarked on courses of action that were inappropriate and continued to persevere in this way in spite of clear indications that their original assessment was wrong. Of course, it is difficult to say how much of this could have been due to SD effects on decision making and not to stress and panic. However, SD certainly played a crucial role in the fateful dawn decision to launch the Space Shuttle Challenger.

What can we do about it

So, sleep is important. Great. But how do you ensure you get enough sleep? Here are a few tips:

Stick to a sleep schedule

I think this is the single most important thing you can do to ensure quality sleep which is why I listed it first. Pick a bed time and a wake up time and stick to them as closely as you can. This helps regulate your body's internal clock (your Circadian rythym), which will help you fall asleep each night and wake up easier each morning.

Of course, life will get in the way of this sometimes, and you shouldn't tell your friends you can't grab a drink because it will throw off your circadian rythym. They'll probably look at you like you're standing on the corner of Senile Old Man St. and Crazy Lady Way. But try to avoid breaking the schedule continuously. Try to at least stick to your schedule on weekdays, which shouldn't be too hard, because, well, you have a job, right?

Shut off your electronic devices

Screens are bright and mimic daylight, and they cause our body to think we're not ready for bed. says using certain technology is bad immediately before bed:

Reading a work email at 9:30pm can keep you up with stress, the blue light from the screens mimics daylight and stimulates you, and you can wake up feeling tired, anxious, and depressed. That’s why you should power down devices at least 30 minutes before bedtime.

Reading email on a smartphone, watching TV or watching a movie on a tablet all stimulate us and can make it harder to fall asleep. recommends not using any sort of technology 30 minutes before bed, and instead to read a magazine or book. If you don't like paper copies of things, reading a book on a tablet is okay (make sure you set it to white on black instead of black on white to limit the brightness), reading on a Kindle E-Ink reader would be better.

Get exercise

It's rather common knowledge that indoor enthusiasts such as ourselves don't get enough exercise. We're not the most coordinated bunch, and a lot of times the sun burns. Exercise is another crucial component to sleep, though. As little as 10 minutes of exercise per day can improve sleep, because it reduces stress and tires you out.

Besides, exercise isn't just important to sleep, it's incredibly important in overall health for many reasons. It's imperative we all get up, start moving and keep moving.

Eat more healthily

Researchers from the Perelman School of Medicine at the University of Pennsylvania looked at how diet affects sleep and they found there is a correlation between length of sleep, calories consumed and variety in your diet. Those that slept a "normal" amount of time, defined as 7-8 hours, consumed an average number of calories. But more importantly they ate a large variety of foods:

Normal sleepers, however, showed the highest food variety in their diets, and very short sleepers had the least variation in what they ate. A varied diet tends to be a marker for good health since it includes multiple sources of nutrients.

Make sure you eat a well balanced diet, that includes some grains, some meat, and some fruits and veggies.

And make sure you lay off the Funyuns.

Have children

I'm only half joking with this one. It's well known by everyone that a newborn actually causes less sleep (I have 2 children, it's definitely true), however once they get to be 6 months or so (a year if you're unlucky) they'll start sleeping better. And what happens is they become a natural alarm - children have this incredible knack for waking up at the same time each morning, regardless of when they went to bed. So, if they always get up at 6:30am, and you, in turn, then always get up at 6:30am, then all you need to do is figure out your bed time and bam, you have your sleep schedule.

Take a sleep aid

This is something I would recommend avoiding because sleeping pills can cause drowsiness, rebound insomnia, dependency and abuse. However some people truly have insomnia and need help sleeping. If this is you, you can talk to your doctor about sleeping pills, or get an OTC aid like ZzzQuil, or get a sleep supplement such as melatonin.

So put down the keyboard and sleep

Rest your eyes, rest your body, rest your mind. You need to recharge yourself, and there's no better way to do that than sleep.

* A friend and I once tried to beat Halo on Legendary in one sitting. It took 16 hours with a few quick pee and food breaks. We finally finished at 6AM and subsequently passed out for the next 10 hours.