DEV Community

Cover image for Improve Your Sleep (as a Developer) 💤

Improve Your Sleep (as a Developer) 💤

Anna Buianova
software developer (web, ruby)
・6 min read

In this post, I won't go into details why sleep is important because there is a lot of information about it already. What I would like to do instead is to share my personal experience of improving my sleep quality and schedule.

I was never a great sleeper: it usually takes time for me to fall asleep, and my sleep schedule goes all over the place if I don't work on it. When I have started working remotely with a flexible schedule several years ago, it became even worse. I would get up and fall asleep later and later each day, it would take longer to fall asleep and I felt like I had less time during the day. I tried different things then but wasn't very successful. I didn't end up sleeping through the day and working through the night but I still got up late, and my schedule wasn't consistent.
The situation changed a lot later when I had my daughter. Then I had to get up earlier but it meant even less sleep! And I don't function well on little sleep (I think that most people are like this, but some of us won't admit it)

There is plenty of advice online and in the books on the topic, but I found out it's often hard to follow, and sometimes it's not applicable "as is", so I had to adjust.

I will go through the things that I tried and share if it worked for me or not.

Have a Sleep Schedule

Almost every sleep-related article will tell you to maintain a set schedule even for the weekends. While that could be useful in general, I found out that I feel better if I let myself sleep in when I can, especially if I was sleeping less than needed several days before. One or two days of sleeping in won't ruin my schedule if I follow the other rules.

For me, the total amount of sleep I get during the week is more important than having a rigid schedule, especially if some kind of "emergencies" happen, and I end up sleeping less one of the nights.

I also don't understand how people manage to improve their schedule by just going to bed earlier. I would never be able to fall asleep like this. For me, the first step to "fix" the schedule is always to get up earlier, be a bit sleep-deprived, and then be able to fall asleep earlier.

However, when I already have a more or less consistent schedule, going to bed at the same time works well. I struggle with following this advice strictly, because on some days I may be less tired and sleepy, and I would get bored by going to bed and trying to fall asleep. I'll describe what helps me with this issue in the next section:

Limit Screen Usage Before Sleep

Popular advice is to avoid using devices several hours before sleep. While that could be useful, it's not always possible or easy to do.
I also found out that for me most problems are caused not by the blue light. The bigger problem is when I browse the internet right before sleep. In this case, I'm likely to be distracted from being sleepy by worrying too much (like these days), or I'll get new ideas and become too excited about them.

So what I do is: avoid devices after 11 pm, except for my e-book. It seems easy, but it was already hard enough to make this habit stick. First, I started with 11:10 and then moved the time a little earlier. I also use a simple habit tracker to watch the progress. This way I read for 10-15 minutes and feel sleepy, even if the book is interesting. Exceptions are outstanding fiction books that can still ruin my schedule :D

Limit Caffeine

This one turned out to be crucial for me. I used to drink several cups of coffee a day without realizing that I was caffeine-sensitive. I used to think that I was just a bad sleeper, that's why I wasn't able to fall asleep quickly 🙈

Later, I experimented a bit and found out what amount of caffeinated drinks I can consume harmlessly. Now I have a small coffee at a coffee shop several times a week, but no later than 12 am or 1 pm. An additional benefit from this is that getting a more quality coffee feels like a treat and cheers me up on days when I get up early.
I can also drink a can of Coca-Cola occasionally, especially if I feel sleepy. It has less caffeine than coffee but works better for me in terms of energy. But Cola is addictive for me, so I make sure to limit it as well. Tea contains caffeine too, but it has less impact on me, so I just make sure not to drink strong tea in the evening.

Be Active During the Day

I don't have time and energy for a full workout every day, but even doing a small one (5-20 minutes) makes a difference.

Another important thing is spending time outside, especially in daylight hours. I make sure to take a break in the middle of my working day and take a walk. Sometimes it's hard to get away from the computer, but I try to do it anyway. Such breaks are helpful in several ways: they give our eyes and brain some rest, provide light exposure, and keep us active. All of these improve our sleep.

Keep a Sleep Diary

That's especially useful when figuring out an optimal schedule and the amount of sleep you need.
Initially, I used paper log and electronic tables to track my sleep, but now it's enough to check sleep records in my fitness bracelet app (though it tends to lie and I need to edit the entries)

These were actions to take when attempting to a set sleep schedule in the long term, but

What to do when you can't fall asleep right now?

Do Mental Exercises

Count sheep? That could be boring, and often isn't effective. At some point, I used counting backward or performing arithmetic operations in my head. This works better because, this way, our brain is occupied but not fully engaged in this activity, so it helps to get in the sleepy state.

Another exercise is recalling what happened during the day step by step. This is suitable for kids too, I used this method with my daughter.
A similar thing is planning the next day, but if you are like me, try not to get too excited or worried about it.

Get Up if you're Unable to Sleep for 30 Minutes (or so)

I don't fully understand this advice. Am I supposed to look at the clock from time to time? In general, I avoid it not to worry about the amount of sleep that is left. And even if I'm not able to fall asleep, I'm usually tired and prefer to lie and have rest even if I'm not sleeping. Sometimes I pick up a book and read for 15 minutes or so before attempting to fall asleep again.

However, I think that it's still good advice and works in some cases, like when you're too stressed and uncomfortable. Getting up, doing something else for a brief amount of time, and then going back to bed prevents our brain from getting stuck trying to fall asleep. But I keep this one for exceptional situations.

There are a lot of other things to try, like:

  • keeping your bedroom dark, cool, and silent
  • using a sleeping mask and earplugs
  • wearing wet socks
  • using a weighted blanket
  • taking melatonin
  • having a ritual before sleep
  • breathing techniques

But I either haven't tried them or thought that describing them from my perspective would be too boring to include in this post.

What about you? Do you use any techniques to make your sleep better?

I would also be grateful for book recommendations on the topic. I've read Peter Spork's book and found it useful. It contains both scientific information behind sleep and practical advice. Unfortunately, this book is not available in English, but you can read it in German or Russian.

Discussion (16)

patricktingen profile image
Patrick Tingen

I try not to do mentally challenging things the last two hours or so before I go to bed. Otherwise my brain won't stop working and I'll never fall asleep. Further, what helps me a lot is just plain old reading a book. I use an ereader (or my oled-phone, no problem with the blue light apparantly) and I read fiction (currently Stephen King's The Institute, which is a fantastic one).

Also, since I try to lose some weight, I do more excercises; every evening I go out for a walk of approx 30-45 minutes, together with my wife. Very relaxing and I sleep better since I started doing it. And lost 6kg :)

lightalloy profile image
Anna Buianova Author

I suppose I wouldn't be able to sleep well after reading Stephen King's books :D

patricktingen profile image
Patrick Tingen

Haha, sometimes reality is much worse...

metalmi profile image
Ivan Almasi

Have a Sleep Schedule

This one is really important. It would be ideal to go to bed and wake up at exactly the same time each and every day.

Limit Screen Usage Before Sleep

You should (at least) reduce blue light, either by software or by using red glasses. Red glasses are better because they also work for room lighting, which should not be too bright.
It is recommended to have a dark period of 3-4 hours before going to sleep. During that time it's good to avoid eating, at least bigger meals.

What about you? Do you use any techniques to make your sleep better?

You should check Polyphasic Sleep.

andy profile image
Andy Zhao (he/him)

Limit Screen Usage Before Sleep

I find this the hardest part to do, but I've been doing what you recommended of "This way I read for 10-15 minutes and feel sleepy, even if the book is interesting" and it's been working well!

lightalloy profile image
Anna Buianova Author

Yeah, taking small steps is the key. When I see "avoid screens for 3 hours before sleep", I know that this is not going to happen! At least in one day :)

lightalloy profile image
Anna Buianova Author

Great idea, not drinking also improves the quality of life overall. It didn't come into my mind because I wasn't drinking on a regular basis in recent years anyway.

michaeltharrington profile image
Michael Tharrington (he/him)

Purrfect cover image.

kongslund profile image
Jonas Kongslund

Regarding caffeine, I want to add that it has a half-life of about 5 hours for most people so the advice of not drinking coffee after 12-1pm pm is very sound.

Caffeine works as a sleep inhibitor so even if you don't have trouble falling asleep, caffeine will still affect your sleep, in particular the duration of the deep sleep phase.

Source: "Caffeine" by Michael Pollan.

Book cover of the audio book "Caffeine" by Michael Pollan

Here's a related article by the above author:

hanpari profile image
Pavel Morava

Anna, as for mental exercises... I have no trouble falling asleep while telling myself made-up stories. Just in my head. I never finish them. 😁

aneeqakhan profile image
Aneeqa Khan ✨

I just hit the heart instantly after watching cover photo 😍

meatboy profile image
Meat Boy

Great advices. In my opinion exercises during the day are the most important for good sleep. Without training or just walk I am feeling tired even after 8 hours of sleep.

ben profile image
Ben Halpern

Really fantastic tips. I'm 100% sure that this resonates with my experiences.

Keep a Sleep Diary

This seems like something that could help close the loop in putting this to action.

zaarthur profile image
Artur • Edited

Isn't cola worse for health than coffee or tea? It is just curious, I'm coffee addict and I try to try other drinks.

lightalloy profile image
Anna Buianova Author

I suppose "worse" can be defined differently. I know that cola contains less caffeine per ml than regular coffee (at least unless it's "cola energy" or smth like that). I think it can affect different people differently too, so we should pay attention to it.