My sleep hygiene as a developer
I’m one of those people who don’t sleep particularly well. My sleep cycle flips continually, if it can. At university, I was on a nocturnal sleep schedule with my natural wake-up time being around 17:00, falling asleep around the time the sun rose. School was quite difficult to fit into this schedule, with the bus leaving at 07:42. I know it was that precise as I'd have to be out of bed and getting ready at 07:28 if I was going to make it on time. Society sadly generally doesn't cater for those with abnormal sleep schedules. So the question is, how do people with such natural rhythms manage to survive?
I'm a sufferer of a disorder that has intense periods of high energy and creativity, usually lasting a month or two, so it’s a little more pronounced for me than the average. During this period, my mind does not rest. Every thought or idea is another I am driven to work on right then, right now. Sleep becomes a frustration, a waste of time when I could be programming, problem solving, or researching. My daily sleep requirement that my mind tells me I need drops to 3 hours, or less. I'll wake and feel as energized as if I'd had 8 hours sleep. But it's all an illusion, caused by confusing brain signals and chemistry. After a month or two sleeping this way, my brain is fried.
To regulate my sleep, and establish healthy cycles, I have to follow rituals.
Programming is not just work for me, it's one of my main hobbies. There's plenty of ideas to turn into realities, not just tasks to complete. Once I start writing code, it's hard to stop. My mind won't switch off, and will keep thinking of possibilities. I code through the ideal period for my body to go to sleep, and end up needing to get back in that zone.
It's not healthy to skip sleeping in favour of doing tasks that involve heavy thinking. Programming these days is somewhat automatic for me, and writing code rarely requires much thinking. But the whole process of converting ideas to code requires a conscious mind. When I'm tired, I find it harder to clearly convey my ideas. Both through code and documentation, or in discussions.
So I set myself a rule: no coding after 21:00. It's an effective rule, and self impose it without doing anything fancy like locking my editor after 21:00. I've noticed that I've slept a lot easier since, but it's certainly decreased my code output. On nights when I code, I'm awake until 03:00 at the earliest.
If I have an idea I'd like to look at during waking hours, I write it down with enough detail that I can pick it up the next day. I'm impatient when I have a good idea, so it can be hard to let it sit. But if something is a good idea, it can almost always wait until tomorrow.
Many people will recommend blue light filters on your screens, which I do find very effective. Some even turn on greyscale so they get discouraged from even using their device. Most of my friends and all my family live far away from me, in different time zones, so not using my devices wouldn't make sense for me.
Beyond my general sleep cycle problems, I have trouble falling asleep. So I take sleep medication to help with that, and listen to familiar comforting videos or audio books to fall asleep. The ideal content is something predictable, either because you've seen it before, or because each episode is quite similar1. The content shouldn't be so interesting that you prefer to watch it than sleep, but also shouldn't be so boring that you'll find it hard to be engaged. Basically, I trick my brain into being entertained but not engaged. Anything with screaming, loud noises, or requires you to actively watch the screen is not a good option.
For the same reason as I avoid programming after 21:00, I avoid gaming at night. Especially anything which has the endless “one more turn” game-play loop2.
Thinking is easier for me when I’ve had good sleep. No chance of headaches, less impatience, and less frustration. When I haven’t had a goodnight’s sleep though, I tell my colleagues. Not everyone wishes to divulge they’re not at their best, but I’d argue the psychological safety required to be comfortable telling colleagues when you’re running low of battery is vital for working together. Trust leads to easier, more honest, interactions.
It’s sometimes hard to reflect on your sleep patterns without data. Tracking when you sleep, and for how long, is pretty handy. The one or two bad nights isn’t too concerning in the big picture, but a repeated pattern of poor sleep will have a big impact on your life. I track as much as I can, and try to figure out how to break any bad cycles.
I’m a sleep walker, talker, texter, eater. From what I can tell, I tend to talk or text if I’m disturbed up by something like a notification, but not fully woken. My texts rarely make any sense, but I can usually reverse engineer what I was trying to say. So I mute many of my notifications, or put them in vibrate only. Walking seems to happen when I’m anxious about something. Eating I’m not sure about, but I find putting food out of reach helpful.
My disorder means I also have periods of excessive tiredness or sleeping. These are managable too, by trying to stick to my regular rituals, but with an additional attempt at waking up earlier than my brain thinks it needs.
I used to have nightmares, which didn’t really scare me, but could be tiring. At some point I learnt to lucid dream3, and now most nights I have multiple dreams that I can remember and control, all quite amusing to me. I often find I’ve sleep-texted my friends when I’ve had a particularly weird and funny dream, telling them the full plot. Since I control the dreams, they’re no longer tiring. I’m not sure if I’d recommend lucid dreaming to everyone, since it could have a negative impact on the dreamer, but for me it’s turned sleep into a permanent safe place. I don’t prescribe meanings to dreams much, but they’re fun to talk about.
Naps can be good for me, they can be bad. It depends how tired I am, and how much potential there is for messing up my night’s sleep. I find that if I have a window open, the sleep is deeper, and more comfortable.
All of this was a description of what I experience, and how I go about ensuring my sleep hygiene is as good as it can be. It’s different for everyone, and there’s a lot of great tips out there. But I often see programmers falling into the same trap as me: coding too late and disrupting sleep.
The real tips I have:
Track your sleep for a bit, and evaluate whether you’re sleeping too much or too little.
Identify the sources of sleep disruption, and impose regulation on yourself to remove them.
Be honest with your colleagues on days when you’re tired.
I hope you found this interesting, or potentially useful!
Some typical things I watch:
Northenlion playing Binding of Isaac
Baertaffy playing Spelunky, or Death Road to Canada
Futurama
The Simpsons
Solar Opposites
Kurzgesagt
Looking at you, Civ 4: Beyond The Sword.
Yes, lucid dreaming is very real, and it’s something you can teach yourself. For me, it came about somewhat unintentionally through unintentional polyphasic sleep, and a dream journal.