I've tried melatonin, cutting out alcohol, f.lux, not looking at a screen for an hour before bed, but the one thing that has had the most influence on my sleep (for the better) is cutting out caffeine after 4pm. (relevant study: http://www.aasmnet.org/jcsm/ViewAbstract.aspx?pid=29198 )
melatonin supplements only go so far. f.lux is indeed awesome. 4pm seems a bit late for me but he has a good point. Also exercise helps a lot ! unfortunately, it also requires the most effort.
Ask HN: Do you struggle to sleep after coding all day?
51–60 of 77 posts
Re: Ask HN: Do you struggle to sleep after coding all day?
#52Otherwise f.lux is a must though it does not work on chromebook or ipad. Nevertheless when I'm really bothered with coding the only thing that will help is melatonin. I take it a few hours before going to bed and it ensures I can sleep reasonably but it makes me too tired to be social late nights and early mornings. The uvex glasses did not have a huge effect on me.
Re: Ask HN: Do you struggle to sleep after coding all day?
#53Re: Ask HN: Do you struggle to sleep after coding all day?
#54Specifically, at least for me, any language that uses character-delimited control structures (ie, curly brackets to begin and end a function as with javascript or PHP) is far more haunting and sleep-stealing.
I have far less of a problem with python or ruby.
I don't know if it's some kind of spacial comfort issue or what, but I've had many nights where I lay away seeing curly brackets on the back of my eyelids, and it's awful.
Other things that have helped me:
* f.lux, as someone mentioned - this has more helped with eye strength, but sleep too
* martial arts (high impact exercise is a great way to change your mindset and get into a new one)
* sex, as someone else broke the ice on (sometimes at the end of a long day of coding I've got a lot of sexual energy)
* acro yoga (nice if you're pair programming because the poses are for two people)
* going for a drive (getting some earth under you is nice)
* taking some time to quietly look at the stars
Re: Ask HN: Do you struggle to sleep after coding all day?
#55Definitely need some time between coding and sleeping, an hour or two minimum for me. When my mind jumps around I try to do focus on a single boring task, like trying to enumerate all 50 states or think of a fruit and vegetable for every letter of the alphabet.
The "Alphabet Game" is something my wife taught me and it works pretty well. The trick is to pick something that is the right level of difficulty: not too hard and not too easy.
Re: Ask HN: Do you struggle to sleep after coding all day?
#56Re: Ask HN: Do you struggle to sleep after coding all day?
#57One big thing is to keep away from caffeine. Caffeine works essentially by slowing the rate that stress hormones dissipate.
You can't really do too much to speed up that process, so the best thing is to stop building more stress. If you have difficulty sleeping, stop trying after 15 minutes and take a break. Do something not very exciting or engaging. Then try again. Similarly do something that stops you thinking about your hard day, for me that's really easy to shut off and takes practice, but for you just try to find something that works, meditation, reading a book, writing, drawing, walking. Just avoid things that are going to build adrenaline like strenuous exercise or competitive video games.
The goal of the previous is to reduce the factors that keep you wakeful. The other side of the coin is that you can increase the state that makes you seek sleep.
Seek satisfactions. Take stock of your body, are you hungry? are you sore? are you dehydrated? do you need to go to the bathroom? Correct these things. They're easy, but you'll make yourself that much more comfortable, and at the same time you'll lower stress.
Take stock of your mind. What is your mind craving? Do you want stimulation? Do you want entertainment? Do you want to socialize? Do you want to relax? When you can, do these things.
This is going to make you feel satisfied.
Sleep crudely works in that there are some hormones that keep you awake, and some hormones that make you want to sleep. Wakeful factors are generally stress-related hormones, which are one of the things that we have most control over increasing, (it's easy to work ourselves up) but hard to decrease (they have a half life in our bodies and can't really be forcibly purged). Then there are restful factors that are generally satisfaction related, seratonin which is crudely a 'things are good' kind of chemical turns into melatonin which is crudely a sleeping factor. Others build up during the day.
Sleep happens when your pressure to sleep overcomes the stress that keeps you awake. I think that keeping that in mind lets you stay healthy.
I think there's a few things we can do in a pinch to help directly too though, but relying on these mean that there's something wrong that you're failing to correct. For instance, a bit of alcohol can be a great way to break the cycle of stress worrying about the day. This can allow your stress levels to drop and even after it's out of your system, you're out of that cycle of worrying. That might get you some better sleep and then you might have a less stressful day the next day.
Similarly, you could take something like melatonin, but again that's artificially taking the place of a feeling of satisfaction and accomplishment. Again, if it's an occasional thing it might be helpful, but if it's covering for the fact that you're always working overly long in an unsatisfying environment and not getting time to yourself, it might be worth it to identify it and work to correct that issue.
That said, everyone's different, and everyone's bodies and brains handle things differently. For some people they might just not properly respond to a normal amount of sleep pressure and have insomnia. For them taking supplements might not indicate anything wrong with their environment, it might just be a quirk of their own personal condition.
But I think we should always look at ourselves first. Not because I'm against supplements, but because it's good to know if our bodies are telling us something. I don't have trouble sleeping, if I go through the process of trying to determine what I'm missing. Whether I'm craving some creative stimulation, or some mindless entertainment or whatever. But generally when I commit to bed I'm asleep within 15 minutes. However, sometimes I realize that there are some things that I need to do to be satisfied that are going to keep me up late. If I had a hard day, I know I'm going to need more time to recover from it, and trying to force myself to go to bed early is just going to make things worse.
Re: Ask HN: Do you struggle to sleep after coding all day?
#58Last night for me was particularly tough. Coded essentially all day, struggled with a bug for hours, and was still on a caffeine high past midnight. The game plan for me should just be to wake up even earlier and wear myself out through more exercise.
Worked 6am to 2pm at my day job. Came home, ate dinner (late lunch) took a 2 hour nap. Went to Starbucks and worked for 3 hours on my side business and had 2 grande coffees - got home around 9pm and couldn't fell asleep until midnight - one of those sleeps where your not really sure if you actually feel asleep.
Coffee, especially strong coffee, can destroy you late at night.
Re: Ask HN: Do you struggle to sleep after coding all day?
#59When I find my mind won't settle down, I'll do 1 of 2 things. If I'm concerned about a list of actions I need to do the next day, I'll write down the list on paper. This allows me to relax and know I won't forget anything. Otherwise, I'll write in my journal about what ever my thoughts are. This allows me to slow my brain down the my writing speed. It lets me process my thoughts. Its helped immensely.