The issues of sleep

Like many programmers (and people experiencing personal difficulties), I have sleep problems.

My usual pattern is that I work or stay up until about 4 a.m. and then crash till 12.

One of the sad parts about this is my peak work period and most creative time is from 9 a.m. to 11 a.m., which I routinely sleep through.

It feels like a “groundhog’s day” scenario sometimes, but I want to change it.

I think one of the reasons this is common among programmers and designers is that by staying up past everyone else’s bedtime you get a sweet chunk of un-interrupted time. The cost is too high though.

I think it negatively effects eating patterns, dietary choices, relationships, mood, emotions, plans, exercise, and basically most of what I want to do.

It is hard to break the cycle though.

Any other thoughts, stories, opinions, or solutions for sleep issues?

My productivity is awful in the evenings and I get distracted easily when I work late. I’ve learned that it’s easier for me to wake up at around 5 and get an uninterrupted block from 5:30 to 10:30 or so. Would that help you?

Yes, that is my "plan."
It sometimes feels like everything is conspiring to prevent me from waking up at a decent hour though.
This is project #1 for me, as I feel sleeping habits are effecting everything else for me.
(Including getting some sunlight.)

I used to have this in the extreme, like most of us here I expect. For the first 28 years of my life I could never remember getting to sleep easily (unless totally intoxicated, but that’s a topic for a different post…). Like a lot of us, I would either lay awake in bed for literally half the night or stay up and work until I simply passed out from exhaustion.

I’m gotten better lately though in the last 5 years. Here’s what’s changed.

  • I got married. Having a spose there somehow made me easier to clear my mind when it comes time to sleep.

  • I got a more rigid sleep schedule: this goes with the first one. We both need to sleep sometime so we end up going to bed at the same time and usually the same time every night.

  • For nights when I know I’ll have problems (like if I slept in that morning), I’ve started using Melatonin. This is tricky, so if you choose to try it, start with the lowest does and work up (like, 250 MICROgrams). The first time I took melatonin I took 3 mg. It knocked me out cold for 18 hours.

…as for trouble waking up, I still have that. I’ve started dealing with it by budgeting “wake-up-time”. Setting my alarm 15 minutes early and when it goes off I don’t require myself to get up, but simply to keep at least one eye open. For me, once I get daylight in my eyes it starts to get the rest of my body going albeit slowly. Usually take 15-20 minutes.

+1 for Melatonin. It’s probably the best sleep aid I’ve ever used.

The biggest thing that helped me with my sleep issues was getting tested for sleep apnea. People tend to associate it with old/fat people but it happens to any and everyone. Losing weight has helped me in every aspect of my life, including this, but I still massively benefit from a CPAP machine. It’s a night and day difference, honestly. Get tested!

Also, I’ve never been much of a believer in how lighting affects sleep until this summer, now that I’m on CPAP. Lately I wake up with the sun around 7:30 naturally, as long as I’m in bed by midnight, even when my alarm is set for 8.

I think light is really important. Sleep and darkness has had a really negative impact on my quality of sleep and life in the last year. My current bedroom does not get any natural light and it’s completely wrecked me.

My wife and I spent five weeks in Turkey at the beginning of the year. Turkey is 8 hours ahead, so when we came back I was waking up at 5am. It was glorious. My life is unequivocally better when I’m waking up early in the morning and going to the gym before work. It’s just so hard to do consistently.

Right now it seems that the problem starts with playing on my iPhone in bed for an hour or so. I think if I left it plugged in on the kitchen counter and read some fiction or something, I’d get to sleep sooner. Working out causes me to be more tired too. It’s a bit of a nasty cycle. Skip the gym, stay up later, sleep in, miss the gym.

I am lucky to live with a sleepologist. Or a sleep tech rather. Some things to try:

  • You will never catch me doing this because I hate oatmeal, but he swears by oatmeal and warm milk before sleep (usually with some melatonin).
  • Pretty much everything on this list:
  • If you think you might have restless leg syndrome, have your ferritin levels checked.
  • If you don’t feel rested after sleep, go see a sleep doctor. You might have sleep apnea.
  • Ask someone to pester you to get off your computer during certain hours (it helps to know someone who works nights and is on their computer)
  • If melatonin doesn’t work try Kava

Not that I am the best at following my own advice, I often have nights where I just plain don’t want to go to sleep. Sometimes I force myself to lay down and count backwards from 100. If I get distracted by a thought, I start over. I usually fall asleep before I finish.


I’ve also struggled a lot with insomnia. There was a time when I just couldn’t sleep at all, like my body forgot how. Here’s what’s in my trickbox for getting a good night’s sleep:

  • Resting time is just as valuable as sleep. If you are horizontal, even if you aren’t sleeping, your body is still getting restorative benefits. Keeping this in mind helps me not be anxious about actually falling asleep.

  • I took melatonin (3 g time released) for several years, recently switched to 5 htp, which I’m liking more. I sleep better and wake up more alert. 5 htp is a precursor to serotonin and melatonin, taking this mimics the body’s natural creation of serotonin and melatonin as needed. (source: The Mood Cure by Julia Ross)

  • Recently also discovered the benefits of getting in bed 30 - 60 minutes before I actually want to go to sleep, turning off the lights and cuing up some podcasts. Lying in a quiet, dark room and engaging my brain so I’m not thinking my own thoughts, really puts me in the mode of a good night’s sleep. I chose podcasts that don’t have lot of bells and whistles that might wake me up if I start to drift off.

  • Consistency in end of screen time and bed time.

Errr… after posting this I had really bad insomnia last night. Its comes and goes for no discernable reason. Really frustrating.

Something that’s been slightly helping me deal with insane late night coding is a little program called f.lux
that changes the “temperature” of your screen during the late hours.

1 Like

I had my ADHD coach mention that I should stay off electronic devices for an hour or so before bed. Apparently the LCD light can actually mess with your melatonin levels.

A quick google search “confirms” this:

I know it’s so hard for us to do that though. I finally settled for reading before bed from a Kindle Paperwhite instead of iPhone/iPad. You can use natural lighting to read from it and there’s a severely limited number of other distractions on the device. (Tweetbot I’m looking at you)

I think insomnia is something that is frighteningly common among software developers, and almost celebrated with all night Redbull and coffee fuelled hackathons. It is something that I struggle with all the time, but I have been controlling it lately using:

  • F.lux, being in front of a computer screen till 3am isn’t helping, try reducing blue light intake after sunset. It is probably better to switch off all screens after 8-9pm but who are we kidding?
  • Sleep alarms, I set an alarm on my phone for 10pm to let me know when I should be in bed.
  • Melatonin, I take some around 8pm, and give it two hours to kick in.
  • Benadryl, When it’s really bad, sleep alarm goes off and I don’t feel tired at all, I’ll take a few Benadryl. This rarely happens once you get used to the new schedule.
  • Crazy alarm clock, If you sleep through alarms, get one that will literally shake you out of bed. The one I have has a vibrating puck that you put under your pillow. I end up waking up 15 minutes before my alarm goes off because it scares the shit out of me.

If you don’t want to go through all that, just give F.lux a try; out of all the things I do I feel it makes the biggest difference. Everyone is different, and I hope you find something that works for you. Keep in mind, that you may just be trying to treat the symptoms, insomnia can be related to other things going on in your life (anxiety, stress, depression, etc).