24

Sometimes I have trouble sleeping after I get obsessed with a programming problem down at work; How do you get yourself back "out of the zone" so you can get a good nights sleep, and solve the programming problem in the morning?

31 accepted

Physical exercise!

26

Get tackled by your 2 year old son as you walk in your front door with him saying "I love you Daddy". Puts the day's tasks into perspective :-)

19

This is something that I've struggled with since college. I remember going to sleep and literally dreaming about code that was stumping me on a programming project. It's the worst feeling to wake up knowing you've gotta face a problem that was unsolved when you went to sleep and was on your mind when you were sleeping.

For me, things that I usually try to do are:

  • Listen to music on the way home. Naturally, most people like music of some sort. Whenever I leave the office, I usually try to listen to some of my favorite type of music. I usually never listen to some type of podcast that is related to software development. I may not be programming at that point, but I feel as if not distancing myself from the problem.

  • Go running. I really enjoy running so I usually got for a run three days a week when I get home. It helps me to clear my head and I can usually think about the things that I need to take care of that evening.

  • Spend some time with the wife. Whenever my wife gets home, she usually likes to tell me about how her work day was. If I've had some issue at work that has put me in a bitter mood (such as not being able to solve a problem), I usually just say that I'll talk about it a little bit later. She understands the nature of programming so completely gets from where I'm coming. We usually try to hang out with each other during the evening - being it taking dogs on walks, playing some videos games, etc. (Of course, all of this can also be done with friends, too. Whatever it most relevant ;).

  • Work on a hobby. I've been playing guitar for a little over 10 years, so I often use that as another form of release. Either learn a new song, focus more on some technical aspect of the instrument (modes, scales, etc), or just jam out for a while.

There are other things that I'll do, too. These are just some examples. Of course, I still like to work on some personal projects at home, but usually not on days where I've had some sort of programming issue at work.

11

I can't, that's why I'm responding at 11:15pm on a Sunday night. It's well past my bed time, but I cant sleep.

Single malt scotch does help sometimes. I wonder if I have some ice in the freezer... back in 5.

7
  • sex
  • drinks with friends (as many as it takes)
  • drinks with work colleagues that don't like to talk about work just like me:)
  • long walks in any "green" area around me.
  • listen to some music while walking home, to get your mind out of the day to day habit
  • listen to another friends problems:) it usually helps me realize that mine aren't so big after all
  • do nothing about it, sometimes it helps to just "sleep on it"
4

Really I don't. I don't know if any of us ever do. The mind will subconsciously work on problems that are "bother" us while we concentrate on something else. That being said, the easiest way to stop working at home is to get into a routine. When you leave the office, stop doing work, and try to stop thinking about it. Do something else not related to programming for the rest of the evening. Exercise is a great way to do this as it relieves stress at the same time, but really any activity that is a divergence from programming/work will do.

It is the same concept as to why it is bad to watch T.V. in the bedroom. By not watching T.V. or reading in the bedroom the body is then trained to understand that when you go to bed it is time to sleep. So one of the keys to solving your problem is to do as little work as possible when you are out of the office. Eventually, your mind will put it aside until you go to work the next day.

2

Play computer games with friends, although that often leads to more computer work anyway!

2

Beer & Rock n' roll

1

I don't know of an easy way! No matter what I try, when I'm trying to get to sleep my mind starts racing and problem solving. Sometimes I let it, because that way I come across solutions or other problems that I had not thought of.

The best thing I have found is a good long walk (focuses on problems) or drinking with friends (thinking of something else).

1

Reading fiction

1

A hard work-out does the trick. So does time spent with friends, family and, especially, my wife ;-).

1

3 letters. S.E.X!

1

Cycling home.

Running the gauntlet of all the nutters on the road trying to kill you effectively wipes the day away with a healthy dose of fear and adrenaline.

And it gives you an appetite: eating a good meal (home-cooked - geeks are the best chefs, hadn't you heard?) a few hours before bed is a great thing to help you sleep too.

1

I love my job, but I keep work at work. I don't go home and think about work problems or complain to family/friends about dumb stuff that happens at work.

1

Riding a bike to and from work is perfect for this. Having to fight for your life in traffic trumps any lingering programming problems that remain in the brain.

0

Stackoverflow...now if I could just get those stupid questions and answers out of my head, then I might be able to get some sleep...

:-)

Full disclosure: I'm answering this after waking...

0

I go and do something not related to programming and that requires some sort of active participation.

To unwind:

go for a walk, go for a drive, go run errands

a tough problem:

go hit a bucket of balls outdoors or in, yardwork - leaves, snow, mowing, home reno project

I do not recommend anything with complexity or criticality when you are hanging on to a tough problem. you will likely be distracted and then have two things that arent going well and this just compounds the stress.

0

Work day? Over? You mean, like, before you fall asleep?

Wow.

0

I go home and code. My trick is staying in the zone on the trip home.

0

I don't normally get this type of problem...my most productive times are earlier in the day. By the time the end of the day comes, I'm already pretty far out of the zone and the last thing I ever want to do is think about work until the next morning.

In the rare occasions when I do have to literally tear myself away from a problem before going home, I tend to turn off my switch by watching TV or playing video games or going out with the wife for an evening at the movies or something like that.

0

Spending time with your family, going out for dinner, reading books, watching movies.

0

I agree with some of the other posts, particularly the music and physical exercise parts.

I keep a few stations or CDs in the car for the ride home which really get me out of the 'corporate' mindset, and really helps me relax. Nothing will get your mind further from the cubicle than a good CD.

Lifting weights is part of my exercise of choice, and having to focus on a particularly difficult lift will force everything else out of your head.

0

I have big problems with this too, but I try to just relax and spend time with my girlfriend when that happens. Do something uncomplicated, like watching tv, watch a movie, play video games etc. I actually don't watch movies which need any amount of brain activity.

0

I upvoted physical exercise. I'll add that it's better to have something that engages the mind as well as the body. Stationary bike is not so good. Walking is better; you have to pay some attention. Hiking over uneven ground is even better. Climbing rocks is better still. I find team sports best of all.

Also worth trying yoga. My yoga teacher often says that if you calm the body, the mind will follow. Unfortunately this works for me only when in class under supervision; I've found the effect hard to duplicate when at home alone.

0

I love playing computer games..mostly i play fifa. Then watch TV, hear music....

0

I usual take some Tylenol PM and fall straight to sleep but then I start to have weird dreams where code and life become one. In the dreams its like walking down the street with a line of code and you come across another line of code and start walking with the other line of code then out of no where an exception runs out attacks us so I have to pull out my debugger and fight back.

0

If you're stuck on a question, write it down. Write down everything you can think of related to the question. Not only will this help you pick it up the next day, but it will usually streamline your thought process and help you figure out the problem itself.

0

I took my personal laptop to work and put it in my drawer and left it there. Now I don't have a computer at home...

Because I don't have a computer I can use at home any more, I've had to find other things to do. I'm studying for my Canadian Citizenship, I'm back at the gym [Consequently I've stopped eating mindlessly], I'm getting to bed at a reasonable hour, I'm getting up earlier and I'm more productive at work because I'm well exercised, well rested and well fueled...

...I'm starting to think I'll leave my laptop at work...

0

Work on a team that practices XP.

You are so tired after a day's pairing, yet satisfied with having achieved something, that swiching off is not a problem.

If that does not work, ride a motorcycle through rush hour traffic for 30 minutes.