DEV Community

Cover image for Sleep More, Code More
Patrick God
Patrick God

Posted on • Updated on • Originally published at

Sleep More, Code More

Yes, you read that right. I know it sounds contradictory, but if you want to write more and better code, you have to sleep more. Let me explain.

Most of us have been there. Writing code all night and spending long hours seems cool, crunch time is great, like a LAN party with code, a hackathon or a game jam. Although you might produce lots of code during these events, you will need a lot of regeneration. But let me tell you when you want to be a longterm successful software developer, you have to train for the marathon, not the sprint.

Programming all night long is not the marathon I’m talking about. It’s more like the marathon of life to sound a little esoteric. Anyway, that’s where sleep comes in. I know it, you know it, it’s common sense. Still, we have to remind ourselves of that fact from time to time. To keep your body and mind healthy, you need enough sleep. Actually pretty simple.

Arnold Schwarzenegger says you should “sleep faster” and only need six hours of sleep. Some say you need eight. I guess something in between is the right amount for most of us. And on the weekends you may be able to sleep as much as you like. I mean even longer, not shorter.

While enough sleep not only boosts your mood and banishes your under-eye circle, it is a key part of a healthy lifestyle and can benefit your heart, weight, mind and more.

As a software developer, you constantly have to learn new things and remember your acquired skills. With enough sleep, you will perform better. It’s more likely you succeed with your craft.

Not only is it easier for your brain to remember things with enough sleep, it also appears to reorganize and restructure your memories, which may result in more creativity as well.

Needless to say that with enough snoozing time you will be able to sharpen your attention and focus much better on your tasks. You will feel less stressed, which has a positive effect on your overall mood and that in turn shows in your day to day life and career.

Arianna Huffington has even dedicated a whole book to sleep where she writes about the life-transforming aspects of the snooze with an impact on your workplace, all scientifically proven, of course.

Now you might already know all this and want to sleep more but simply have problems to fall asleep or to sleep through. There are ways to fix this if you haven’t tried them yet.

As we are in a technical environment here, chances are you are looking at your smartphone right before you switch off the lights and go to sleep. Try to put your phone or any other devices away a bit earlier, maybe even an hour before bedtime. The screen keeps you awake.

Apart from that, you might try to set up a proper sleep environment or even an evening routine. This means, pick a time where you want to prepare to go to bed. You could start by taking your shower and brushing your teeth and while you’re doing that, you already opened the windows of your bedroom so that it can cool down. A cooler room leads to better sleep. If that’s not enough, you can also try one of those cooling mattress toppers Tim Ferriss recommends in his book Tools of Titans (although they are pretty expensive).

When you’re done in the bathroom, make yourself a cup of tea, grab your favorite book (novels seem to work best), dim the lights and enjoy this incredibly cozy time in your bed. You will probably get sleepy much faster and after half an hour or so you want to turn off the lights and just sleep.

Besides, you should really leave it at the tea and not drink coffee or alcohol just before going to bed. Alcohol may help to fall asleep, but the quality of your snooze is much worse.

Do you have any evening routines or tips to improve the quality of your good night’s sleep?

The post Sleep More, Code More appeared first on Programmer Goals.

But wait, there’s more!

Top comments (23)

philsinsight profile image
Mr. Boateng

Great post! really great advice thanks!

I'm trying to improve my sleep, I use a Fitbit tracker to monitor my sleep and my average is currently 5 hours 👀. One thing that definitely helps is to leave all your distracting devices in another room.

I also often hear that 8 hours sleep is a goal that can be reached in one consecutive sleep cycle, or broken down and achieved throughout the day.

So if one were to sleep for 5 hours in the night, the idea would be make up for the lost sleep throughout the day, which may also be where the idea of power naps derive from.

would be good to hear your thoughts on this 👍🏽.

petersimnz profile image
Peter Sim

Many lifetimes ago, before the Internet was ubiquitous, I was an aficionado of cryptic crosswords. Many evenings I would puzzle about particularly difficult clues. More times than not, the next morning the answer was glaringly obvious.

With coding there's often a tendency to keep going to solve the next problem and before you know it, the wee small hours are there.

I agree with the "Sleep More, Code More" premise. Even though you are asleep, your mind and brain keep working and when you're rested, you do look at seemingly insoluble problems with a fresh perspective.

_patrickgod profile image
Patrick God

So true! I can't count the many times I struggled in the evenings and suddenly out of nowhere, the perfect solution came up the next morning.

Thanks for sharing. :)

ponach profile image
rachid el kedmiri

The secret is to listen to your body, meaning if you need sleep then sleep.
Falling asleep quickly is overly underestimated, if done right you will save valuable minutes in which you are probably just staring at your room's ceiling. for me personally, once I lay down I don't don't do a thing -no phone, book, ...- and after a couple of weeks once lay down I pass out -my body is now programmed to rest I guess hehe-
My advice for those struggling with falling asleep quickly is to have patience and once in bed don't do a thing not even reading a book; sooner your body will be programmed to fall asleep within minutes (it takes me now less than 2 minutes to fall asleep).

cantavest profile image
Rosanna Cantavella

Excellent advice, Patrick! We all need to sleep well. As to routines for going to bed:

(a) When? I'm a lark, not an owl. Once I confessed this to myself, my life became easier. My brain works much better in the early morning, so I go to bed at 9:30 pm, and am able and ready to work about 6:30.

(b) How? Yes, good advice: avoid screens in bed. Lighted screens, should I specify, as I read on my basic, ink-screen Kindle and have no problem at all. As to which genre, I try to avoid fiction, as I get hooked and can't stop reading! I've found essays, or even poetry (yes, poetry) much more conducent to sleep.

_patrickgod profile image
Patrick God

Thanks for sharing your tips! It's true, a Kindle is a great exception. It works pretty well. I for myself often read kinda self-help books before going to bed (although it might not always be the best idea...). Maybe I should give poetry a try. :)

And regarding the time you're going to bed: Thank you! Sometimes it still feels awkward to be in bed and I see that 9 on the clock. But then again it's great to know that I can enjoy this lovely time knowing I will have a fresh mind early in the morning.

dbell154 profile image
Dana Bell

I've discovered two things about myself. First thing is I've learned that power naps (5-15 minutes) can help make up for some loss sleep the night before and make me more alert.
Second thing is I've found a benefit in drinking coffee in the morning. One or two cups in the morning helps me get to sleep that night. It's like there is a crash after all the caffeine has been used up.

prototowb profile image
Tobias Rauer • Edited

that sounds nice and simple 😌
power naps unfortunately don't work for me - I'm totally exhausted after waking up and need around 2h of real sleep, so the whole day usually is "%/&ed.
Coffee is also difficult, since it somehow makes me tired instead, when I drink it midday or more than 2 small cups (heard people with adhd have this problem, never got tested).

rurban profile image
Reini Urban

And don't forget the mandatory afternoon siesta. After doing that my github contributions stats did skyrocket, ~2900/year.

jillesvangurp profile image
Jilles van Gurp

No caffeinated beverages after lunch for me. I've learned the hard way that I sleep poorly if I don't stick to that rule. Which in turn means my productivity crashes the next few days because I'm too tired to function. I find actually closing my laptop and going home is often the fastest way to resolve seemingly unsolvable issues that just melt away the next morning; often in minutes. This has happened so often to me that I tend to just bet on this working instead of working late these days. In the same way, making the most of small breaks or weekends makes a difference when you come back to work.

Crunch time is a thing in our industry. But it has a cost. You are trading off short term productivity vs. mid term productivity. It's that simple. Crunch is inevitably followed by a crash. I'm not saying don't do it but be mindful that there's more to a project than surviving the next 48 hours by drinking too much coffee, not sleeping, and frantically trying to solve whatever problem needs solving. And BTW. your ability to do that completely tanks when you are tired.

I enjoy a good crunch once in a while but I compensate by mindfully slacking & procrastinating right after and taking time to get back to my normal routine.

_patrickgod profile image
Patrick God

Thanks for sharing your thoughts on this. :)

I'm totally with you. If I have coffee after lunch, I still feel it in the evening. Currently, I even try to ditch the coffee and only drink green tea in the morning. Tastes great!

I also understand that you enjoy a good crunch. Sometimes, I also just love the grind. That feeling when you flow in the zone and don't want to stop. It's a great experience once in a while, but as you mentioned, it's crucial to also have a good portion of relaxation after.

hkly profile image
hkly • Edited

I've been using F.lux,, to filter out the blue light from my screen in the evenings so the screen light isn't as harsh as I code later in the day. You can customize the amount of filtering you want throughout the day and have the filter get stronger as the sun sets. There even is a feature that super filters your screen at 8 hours before your set "waking time" that serves as a reminder that I should probably get off my computer and go to sleep!

darthmaul profile image

Cannot say enough good things about f.lux! It's a great program and every dev should be using it or something like it!

caffeinatedcake profile image

Very nice article, I enjoyed reading it. It also reminds me (again) that I should really make a real effort to tidy up my sleep schedule.

Since the subject seems to appeal to you, I'd like to recommend a book (if you didn't already read it, of course): "The Power of When", by Micheal Breus.

It was a pretty good reading that allowed me to start paying more attention to my bad habits regarding sleep, and has a lot of good advices on the subject. You might enjoy it too.

_patrickgod profile image
Patrick God

Hey, Thank you very much. Also for your book recommendation. I will have a look at it. :)

stephaneeybert profile image
Stephane Eybert

Drinking tea before bed time would prevent me from falling asleep as it contains cafeine.

karfau profile image
Christian Bewernitz

Good hint. But that's only true for black/ green/ white tea, but not for tea made from herbs/ fruits/ rooibos/ ...

wilsmart profile image
Wilmar Alberto Martinez Perozo

Thanks for the advice!

_patrickgod profile image
Patrick God

You're welcome! :)

nateous profile image

So I should stop reading this article an hour before bed... Great article!

seyfer profile image
Oleg Abrazhaev

make yourself a cup of tea

bad advice. green or black tea still contains caffeine. so if I want one before the bed I have only fruit or grass tea.

_patrickgod profile image
Patrick God

What about chamomile? ;)

seyfer profile image
Oleg Abrazhaev

Yes, sure. Anything without caffeine suits for me. :)