Computer programmers: How do you sleep at night?
September 20, 2016 6:47 AM   Subscribe

If I don't get a programming problem solved before bedtime, my brain keeps waking me up, trying to solve it. This makes me very tired. Others who have dealt with this: How do you shut your brain up for sleepy time?

When I was younger, I'd "solve" it by simply staying up all night until I had the problem solved and the task accomplished. But now I have a kid, and that's not an option.

I don't do a huge amount of programming, but I've started a project at a new job, and I'm tired.
posted by clawsoon to Health & Fitness (23 answers total) 4 users marked this as a favorite
 
I find it's important to have a good stopping time, 5pm works pretty well, where I don't think about what I'm working on at all anymore. I read a book on a totally unrelated subject or go to the gym or meet friends at a bar or just zone out in front of netflix (truthfully, also, lots of MeFi), so that by the time bedtime rolls around, I'm more worried about the question we couldn't find an answer to on trivia night than I am about how I'm going to solve the persistent bug that only 1 in 10 users report and can't be easily reproduced.
posted by dis_integration at 6:55 AM on September 20, 2016


I learned the following, uh, work-hack from some guy's blog: stop every day at something trivial, even make like a compiler error for yourself by not having a semicolon, or something like that, if you have to. Then, the next day, you know exactly where to pick up and what to do. Hopefully, this will get you back into the zone smoothly: you start out by getting something little done, not be resuming in the middle of some perplexity.
posted by thelonius at 6:58 AM on September 20, 2016 [17 favorites]


Kids are a good reason to leave work at a fairly fixed time. I found it was useful to have some kind of quick debrief with myself at the end of the day where I tried to consciously summarize what I knew, what my theory was about the problem and what I was going to try next. After that I'd try to do something else, like dis_integration suggests.

If you need to justify this to yourself you can tell yourself that you will probably solve the problem quicker the next day after your subsconscious has worked on it for some time.
posted by crocomancer at 7:02 AM on September 20, 2016 [2 favorites]


I totally know how you feel. I've been a programmer for a decade and yeah, this totally happens. That said, I also have the tendency to obsess over all aspects of my life, including coding issues.

My solution is to read until I fall asleep. I keep the light fairly dim, just enough light to be able to read my kindle, and I read in a super comfy tummy-down position. I usually allow myself 1 or 2 nodding off occurrences before I finally give in and turn off the light. By that point I am so tired that I drop off quickly. My brain has nothing left to obsess over anything.


Alternatively, I will spend the last 15 minutes of my work day not programming but writing out a list of ideas to try the next day to try to solve the issue.
posted by PuppetMcSockerson at 7:04 AM on September 20, 2016 [3 favorites]


I take thelonius' approach: find a point where you know what needs to fixed next and leave it as your starting point for the next day. Having said that, I am not sure I would go as far as creating a problem to be solved; I don't think my brain is that easy to fool.

For those extreme cases where the next step is as clear as mud, I shelve my work and then spend my last hour/30 mins in the office working on something trivial. This also has the benefit that the solution for the difficult problem usually pops into my head when I'm in the shower the following morning.

In addition, I agree with PuppetMcSockerson that spending a short while reading in bed pays dividends when it comes to getting a good night's sleep.
posted by oclipa at 7:26 AM on September 20, 2016 [3 favorites]


Thirty-seven years in IT here. I realized I couldn't shut the problem out of my mind completely, but I could offload my thought so it could be dealt with when I could give it my complete attention. I did this by writing down my thoughts when/if they came to me and then returning to whatever I was doing, kind of like the GTD technique of recording things you need to do as they come to mind and then forgetting about them. Keep a notepad handy, even by your bed. It's hard at first but you learn to trust the method and yourself.
posted by davcoo at 8:38 AM on September 20, 2016 [2 favorites]


That's a tough one. Willpower and set hours, which is just willpower again.

I have found that getting too drunk and stoned to work is a good way, albeit not the healthiest solution.
posted by humboldt32 at 9:23 AM on September 20, 2016


SysAdmin here.

Not exactly a programmer, but I'm faced with this all. the. time.

Weird edge-cases ruining my scripts, etc. are the mother of like, terrible hacky solutions to things that come back and bite me in the ass a year later.
posted by Oktober at 9:26 AM on September 20, 2016


As someone who used to do the all night thing regularly, I think you have to view intermediate steps as part of the overall solution. I think there is often a tendency to rush it all out to preserve the conceptual "elegance" of the idea but often this elegance is a bit of a mirage and so it's better to treat the process as a long journey where each step is part of the overall plan. This gives you natural stopping points that can represent legitimate accomplishment. It's also important to recognize that knowing how to organize the creation of complex software as well as the actual code itself are skills in their own right, separate from actually writing code, and so this is something that requires experience. I think part of the reason I don't do the crazy overnighters anymore is that I'm closer to 20 years in than not at this point in my career so not much surprises me and I generally already have an idea of the basic shape of the solution to a wide array of various problems. Reading blogs and books such as Beautiful Code that focus on the low level mechanics of how large scale apps have been built can help here but it seems like getting in shape, you just have to do the work and over time it subtly becomes easier.
posted by feloniousmonk at 9:43 AM on September 20, 2016 [1 favorite]


No clue. I usually go to bed at 11, and then wake up at 3 and putter around trying to figure stuff out, and then sleep 4-7 or so. Not too healthy.
posted by miyabo at 9:46 AM on September 20, 2016


I do it with a little mantra: "Sleep matters more now."

Sleep matters more now.
Sleep matters more now.
Sleep matters more now.
Sleep matters more now.
Sleep matters more now.
Sleep matters more now.
Sleep matters more now.
Sleep matters more now.
Sleep matters more now.
Sleep matters more now.
Sleep matters more now.
Sleep matters more now.
Sleep matters more now.
Sleep matters more now.
Sleep matters more now.
posted by flabdablet at 10:09 AM on September 20, 2016 [2 favorites]


Some businessy/self-help listicle I read a while ago recommended making a promise to yourself that you'll pick it up in the morning. It might also help to write the problem down (without getting back into trying to solve it).

If you write down the problem before turning out the light and leave it on your bedside table, it'll be there for you to resume work on in the morning. It doesn't need to live in your head for the night.
posted by boghead at 10:44 AM on September 20, 2016 [1 favorite]


Nthing discipline, and having a notebook nearby to take notes when inspiration strikes. Otherwise, I try to read to put myself to sleep if I'm really stuck.

As someone who works at home, this is a constant problem - I can always swing back by and just take one more look!
posted by getawaysticks at 11:17 AM on September 20, 2016


You say that you are tired. Soon enough, I would have thought, fatigue will kill your problem-solving ability.

If I were you, I would make some plans to have a stopping time, and physically walk away from your computer. Always carrying around something to write on just in case you have an ah-ha moment is a good suggestion. A mobile phone with a camera is ideal for this. You can draw a sketch on a whatever you have to hand, take a photo, and email it to yourself ready for the morning.

There was once memorably a shopping list kicking around our apartment which went

- Thing to buy 1
- Thing to buy 2
- Try out method X to solve Y programming problem
- ...

by which I mean, I do understand how a niggling programming problem can get inside your head and haunt you at odd moments.

For some reason, this seems like a good moment to mention Rubber duck debugging, in case you have never heard of it. You might find the concept useful, now or in the future.
posted by Erinaceus europaeus at 11:50 AM on September 20, 2016


Keep a notebook by your bed and write down the key points of the solution in your head to get it out of your head. Trust your future (next day) self to understand the notes and pick it up from there.
posted by matildaben at 12:01 PM on September 20, 2016


i don't really have this problem - i think partly because i tend to think up solutions when i'm asleep or in the shower the next day anyway. once you realise this, and trust it (which i guess is the hard part) it's more like "ok, unconsciousness, this is your problem now; i'll go and read reddit or whatever."

another way of saying the same thing: what's driving you to search for a solution is the fear that you won't have a solution next day. but generally, if you get a good night's sleep you *do* have a good solution. so why worry? more than that: it's better not to worry.

also, stop trying to solve problems by running round in circles like a squirrel on speed, playing with every little detail until it works. that's a really dumb way to solve problems. it causes more work than it helps. take things slowly, and wait - don't write anything - til the idea is clear in your mind. and, again, experience will show that getting things clear in your mind is best done by relaxing.

in short: think of relaxing as something positive. something you actively do as part of solving the problem. know and trust yourself.
posted by andrewcooke at 12:06 PM on September 20, 2016 [3 favorites]


Reward and celebrate when your lizard brain (unconscious) solves a problem in the morning. To do that fill up the front worry wort brain with details, explicitly telling it to NOT TRY to find a solution. Remind that front brain that the lizard is really part of it and it's important to feed the lizard overnight.

oh and generic nyquil :-) (infrequently)
posted by sammyo at 12:27 PM on September 20, 2016


"It is amazing how much both happiness and efficiency can be increased by the cultivation of an orderly mind, which thinks about a matter adequately at the right time rather than inadequately all the time."

Bertrand Russell, Conquest of Happiness
posted by wittgenstein at 3:01 PM on September 20, 2016


This might be of use, with their science here. I've actually found it to sometimes be of help when my mind won't stop with linear problem-solving.
posted by WCityMike at 3:24 PM on September 20, 2016


The last thing I do before I leave my desk is write down where I'm at. Writing on a piece of paper:
What is working, what is not working, at what point it is breaking or I think it is breaking and what I might check for in the morning. If I'm debugging and I'm curious about a particular line of code to check in the morning, I'll put a "zzz" in the front of it (so it doesn't compile and I know where to start looking). This way I don't have to remember anything, I can let it all go for the evening. It only took my about 20 years to be able to let it completely go. Good luck.
posted by falsedmitri at 7:08 PM on September 20, 2016


In addition to the excellent advice on brain-dumping the problem somewhere before you stop, I'd advise keeping both physical and mental separation from your "work" spaces and "rest" spaces. Try to avoid doing work where you sleep or relax, and allow yourself some time to decompress before you try to sleep. Occupy yourself with something relatively mindless but distracting enough to keep your thoughts from wandering back to the problem; usually watching videos does this for me (I find Bob Ross videos are a very good sleep aid), but things like chores or reading or playing low-stress games might do it for you. Melatonin taken about an hour before you want to go to bed might also help.

Also, if I've been at a problem for too long without a break, I know for a fact my output suffers in quality. View all this as a way to do future you a favor, both in terms of tiredness, and in terms of not writing dumb, hacky code that you don't remember exactly how it works.
posted by Aleyn at 9:09 PM on September 20, 2016


If you have trouble falling asleep once your head hits the pillow, there are some really good guided meditations available from Insight Timer, which is a smartphone app. I use it nearly every night.

This is my favorite guided meditation to fall asleep to; it's available on the app, and also on YouTube. It's by Franko Heke: True North Guided Sleep Meditation.
posted by spinifex23 at 1:18 AM on September 21, 2016


Great suggestions above. I also try to cultivate other things to think about when my mind churns at night - something calming and relaxing that also lends itself to focus: "you are in a forest/on a beach/in an inn in a tiny village - carefully imagine and describe everything in your calm, peaceful environment, in great detail." That can help.

If that doesn't work, I find that BBC podcasts (In Our Time is perfect) give my mind something else to focus on, and the (usually) calm voices lead me right into sleep.
posted by kristi at 9:38 AM on September 23, 2016


« Older Best ways to handle someone who is suicidal?   |   Awesome Grad School vs Mental Health Newer »
This thread is closed to new comments.