Ask HN: Do you struggle to sleep after coding all day?
Anybody else suffer from the same? How are you switching off before you go to sleep?
Anybody else suffer from the same? How are you switching off before you go to sleep?
With that said, last year I was talking to my doctor about it at my annual physical. He suggested I exercise more often. So for about the last 6-7 months I have made a conscious effort that whenever I feel like I am starting to struggle I will go out for at least a 30 minute walk. I usually end up taking about 4-5 a day. There is definitely a direct correlation between the amount I walk and my productivity. And I am starting to sleep a whole lot better at night. Another thing that has helped me is I stopped drinking soda and now only drink water (or coffee).
Those are worse than no sleep. You sleep all night feeling like you're struggling with this mammoth problem or even worse having a breakthrough in the problem, then wake up feeling tired and can't remember whether your revelations were real or figments of your imagination.
Anyway, I used to have those a lot in school, when I was working towards more solid deadlines and literally fell asleep coding. They've happened once or twice since I've been out and working and I've learned that it's better to put the problem down and walk away than to spend my free time or sleep time trying to solve it. That's only going to lead to an unproductive day the next day, when I actually have my tools in front of me.
Occasionally, I'll be watching TV after work and the solution just pops into my head. A relaxed mind is a creative mind. Even then I won't pursue it, just make a note to investigate tomorrow.
Pick a time for a week and go to bed then regardless of anything else. Try to limit light exposure for the hour before sleeping (no phones in bed) and see if that helps. The more consistent you can be, the more consistent your sleep will be.
Additionally, the Sleep as Android app makes for a great way to track and log sleeping patterns, and has a nice adaptive alarm.
If you have trouble sleeping then it is a very good rule.
Specifically, 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
Err ... to proactively eliminate parsing errors:
Is anyone other than me going to suggest sex as a strategy on this public internet forum?
Unless your workplace is much more interesting than mine it is a change of pace from day to day work, I guess it counts as light exercise, its fun and stress reducing unless you're doin it wrong.
I've been taking a melatonin supplement lately - it's helped. Cut back on your coffee intake if you drink coffee and try to work out for 10-20 minutes, even if it's just going for a walk or a light bike ride.
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.
1) your bed is for sleeping and sleeping only. Not all of us are lucky enough to have a separate room for work and sleeping but at the very least, don't even think of taking work to bed. Be it laptop, or phone, your bed is sacred. It is for relaxation only. Which is generally why using a phone before sleeping isn't a great idea. Our phones and our activity on it have become part of our daily routines. The whole idea of going to bed is to separate from the rest of the day.
2) exercise. Your body can only go so far. Exercising well ensures that come night, your mind will be telling you to just go the f* to sleep.
3) time block yourself. Do not operate with flexible time slots. Set a routine, and set the times. I've found that 1 hour focus time (turn off the internet if you have to) will see yourself getting more done than if you were to kind of free flow for 3 hours just because you have 3 hours available to yourself. Our brains our crap at sticking to something unless given very specific parameters to operate within, so set those boundaries. Ideally, your time slot should end 30 minutes before bed latest. It doesn't matter if you haven't finished the problem at that time, write a comment which has the set of steps you want to try out, and switch off. No buts. This practice will not only help your brain get trained to switch off, it'll also train yourself to focus better (I guarantee the latter)
4) if you find yourself mulling over what to do tomorrow, follow what others have said. Write your stuff down, and turn over. No googling. Nothing. Got something to google? Write that down too. Your brain will eventually recognise that it doesn't need to take on the overhead of tracking tasks. Or be like me. Forget about what you have to do and wait for someone to remind you :D :D (the latter is NOT for real. Don't try that at home or anywhere else :D )
Point taken, but can we expand that list by one? ;-)
At least I know the pattern. A problem without solution is already solved: I just pick up a good book and wait it out, knowing I'll be sleepy the next day.
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.
Otherwise 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.
Now I just take Melatonin in the evening ( http://www.gwern.net/Melatonin ) and sleep somewhat normally.
EDIT: I also use the flux app, and I reduced my coffee consumption significantly, now down to zero, but melatonin had the quickest and most observable effect.
A few things I've found that help me: - Exercise. I work out 8-12 hours/week. Being physically tired makes sleep easier. - Eat dinner >2 hours before bed and avoid late snacks. - No alcohol (I do have an occasional drink, but it always impacts my sleep) - No TV in bedroom. I either read for 30-60 minutes or talk to my wife until we doze off.
When do you exercise though? I find exercise before bed makes it easier for me to sleep but others I've spoken to seem to get too pumped up!
Maybe try reading before sleeping- or something that can take your mind off the day's activities (that's probably what winds up happening with me).
Look up the "body scan" method (it involves resting your attention on & relaxing each individual group of muscles in your body). Puts me to sleep without fail.
Apparently currently I am doing this.
One 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.