I once saw a program (can't remember which) where it talked about people "experiencing flow" when they are doing something they are passionate about. When "in flow", they tend to lose track of time and surrounding, concentrating only on their activity at hand.

This happens a lot for me when I program; most particularly when I face a problem. I refuse to give up until it's solved. This usually leads to hours just rushing by and I forget to eat lunch, dinner gets pushed into far into the evening, and when I finally look at the clock, it's way into the wee-hours of the night and I will only get a few hours of sleep before having to rise early in the morning. (This is not to say that I'm in flow only when facing a problem - but I find it particularly hard to stop programming and step back when there's something I can't solve immediately.)

I love programming, but I hate it when it disrupts my normal routines (most importantly eating and sleeping patterns). And sitting still for so many hours, staring a screen, is not healthy.

Please, any ideas on how I can get my rampant programming activity under control?

  • 7
    I always thought being "in the zone" was when you are in a very productive state i.e. solving problems left and right and getting a lot of progress made,instead of being stuck in a problem for a long time.
    – MAK
    Commented Oct 7, 2010 at 10:58
  • @MAK: That might be the correct meaning of it, yes. The term I was looking for was flow, as explained by one of the answers. I've updated the question accordingly.
    – gablin
    Commented Oct 7, 2010 at 13:51

14 Answers 14


Get married

A partner yelling "Dinner is ready." or "Get to bed now, or you'll be grumpy in the morning" will kick your right out of that zone.

Seriously. The only reason I get to bed on time is because my wife hates me in the morning after late nights of programming.

There's other benefits too.

  • 3
    The only reason we don't live in caves are the need for electricity and marriage.
    – JeffO
    Commented Oct 6, 2010 at 21:11
  • 11
    And then have kids, and spending lots of time programming will be very far down the list of your problems. Commented Oct 6, 2010 at 21:12
  • 3
    Nevah shall I let no woman bring me down! ... Sigh I need to get out more...
    – gablin
    Commented Oct 6, 2010 at 21:51
  • 3
    @gablin: lol. A good woman (we'll say partner to be more inclusive and correct) will always bring you up! Commented Oct 7, 2010 at 21:07
  • 4
    But what if your wife is also a programmer? (Also, +1 for "there's other benefits too", lol). Commented Jul 7, 2011 at 15:17

Drink lots of water. It's good for you, and it causes certain urges that are difficult to resist.

  • 1
    Yes, I should drink more water. The only problem is, I would only forget about it while coding. Maybe if I combine this with Levi Hackwith's answer...
    – gablin
    Commented Oct 6, 2010 at 19:13
  • Start smoking then :)
    – user1249
    Commented Oct 6, 2010 at 19:18
  • 3
    Bottle of water on the desk next to you. That'll help remind you. (A bottle, because you can close the top - you don't want spills!) Commented Oct 6, 2010 at 19:21
  • 1
    Diet soda with caffeine works well too, as it's mostly water, and the caffeine only increases those certain urges.
    – Kyralessa
    Commented Oct 7, 2010 at 4:40
  • While this answer is a good habit in itself, I don't understand how this would really solve my problem.
    – gablin
    Commented Oct 7, 2010 at 13:54

The mental state you're describing sounds like Flow, a phenomenon studied extensively by the Hungarian Psychologist Mihaly Csikszentmihalyi. Briefly, its main characteristics are:

  • Clear goals
  • High degree of concentration on a limited field of attention
  • Loss of self-consciousness
  • Distorted sense of time
  • A sense of personal control over the situation or activity.
  • The activity is intrinsically rewarding, so there is an effortlessness of action.
  • A lack of awareness of bodily needs (like hunger or fatigue)

Computer programmers seem to be better able to achieve Flow, and it has been hypothesized that people with an autotelic personality are also better able to achieve Flow.

Flow is generally considered a positive experience correlated with maximal productivity. In his book Emotional Intelligence, the psychologist Daniel Goleman wrote, "The hallmark of flow is a feeling of spontaneous joy, even rapture, while performing a task."

So, given all that, why on earth do you want to stifle it? My advice would be to savor it and foster it as much as possible.

However, given that you want to extirpate Flow, here are a couple of ideas:

  1. Boredom and anxiety block flow. So cultivating these mental states might work. But I highly recommend against it.
  2. There are a few conditions that make flow possible (clear goals, balance between your skill level and the level of the challenge, and the task you're working on must have immediate feedback). Getting rid of any one of these conditions may also get rid of Flow.
  3. In my personal experience, Flow decreases in frequency and intensity with age. So you may just want to "wait it out."
  • Absolutely brilliant answer (even the Discovery Channel first part, but I really enjoyed the ways to "extirpate Flow")... +1 Commented Oct 7, 2010 at 4:57
  • 3
    Ah yes that's what it was called! I thought "zone" sounded a bit off; flow, that's it. Well, again, I'm not trying to stop it from happening; I'm just trying to stop it from interferring with my normal routines and health. If I were to "foster" it even more, I'd sit in front of the computer from morning till late night. With no breaks. And no food, water or stretching of toes. That's really not an experience I want. Furthermore, I find that I'm able to solve a problem much quicker if I'm allowed to step away from it and clear my head with something else.
    – gablin
    Commented Oct 7, 2010 at 9:18
  • 1
    I don't believe (at least I hope so) that flow decreases with age. I'm 46 yoears old now and still enjoying it :-)
    – chrmue
    Commented Mar 28, 2011 at 12:58
  • 2
    Speeking as someone who has suffered from this also, I'd say that this post, although good and informative, is proof itself that psychologists don't have a clue when it comes to the difference between a psychologically interesting phenomenon and what is good for your health. Commented Oct 30, 2011 at 1:22

Set a timer. Plain and simple. Use this timer to break up your activities and prevent you from not eating, sleeping, etc.

  • 1
    I've been thinking about this too, but never gotten around to try it. And my egg clock scares the shit out of me everytime it rings. XD
    – gablin
    Commented Oct 6, 2010 at 19:10
  • 3
    Install WorkRave and you can get a reminder to stop as well as avoid repetitive stress injuries! Commented Oct 6, 2010 at 23:10
  • @dash-tom-bang: This looks promising. Will try it out next time I'm coding. Thanks!
    – gablin
    Commented Oct 7, 2010 at 13:57
  • the trick that did it for me was: you have to programm, or at least script and configure your own timer. i did it with remind, notify-send, play, sendmail and some other *nix utilities. this way you get it liek you want it, at it feels more like "ahh yeah i shoudl go to sleep now, thank you, myself!" instead of "stupid timer! dont't push and scare me!"
    – hoijui
    Commented Jun 21, 2015 at 8:14

I love when that happens... That's what I hope for every time I sit down to code. If I were you I wouldn't try to stop it, you might be wishing for it later.

  • 2
    Well, I'm not trying to stop it from happening; I'm just trying to stop it from getting out of hand. ^^
    – gablin
    Commented Oct 6, 2010 at 19:11
  • 1
    Move your clock more in to view? Get a bigger one?
    – Fosco
    Commented Oct 6, 2010 at 19:41
  • You know, that's quite a good idea!
    – gablin
    Commented Oct 6, 2010 at 21:48

All of the other answers to this question just focus on tricks to interrupt you, to remind you to stop: get married (so someone will force you to stop), drink water (so the urge to urinate will force you to stop), set a timer (to remind you to stop). These are all gimmicks and don't address the core problem.

"Flow" may be a real thing, but it isn't a magical super power. At some point you need to sleep. The thing keeping you at the keyboard, even when you're exhausted, is fear. You're afraid that if you stop now, you won't have time to finish tomorrow or you won't remember where you left off. When you're tired, the problem starts compounding: it's harder to focus, so you become less effective, so it takes you longer to accomplish things.

How many times have you worked until the wee hours of the morning, struggling with a problem, only to give up in defeat, feeling miserable, then after a night's rest, a solution occurs to you the moment you return to work? That's not luck. That's a pretty big clue that the time you spend away from the keyboard is as important as the time you spend on it.

You need to learn to trust that you will work more efficiently if you work on a regular schedule, and get rest, than if you treat your work as something you need to keep plowing through as quickly as possible. It sounds simple and you may even agree with me now, but it takes some work to learn it on the level where your unconscious mind doesn't fight with you as soon as you are tired with unfinished work left to do.

  • 1
    +1 though I don't necessarily agree that the motivating factor is fear. It isn't for me at least. For me it's exactly "the time you spend away from the keyboard is as important as the time you spend on it.". It's a matter of keeping your priorities in focus. Commented Oct 30, 2011 at 1:25
  • When I am in a flow state, I feel complete joy. I am not aware of time passing, missing meals or muscle aches from not moving.
    – user87105
    Commented Feb 5, 2014 at 6:51

What you seem to want is a more controlled way of working, whilst still actually being productive with your programming?

If so, have a look at The Pomodoro Technique where you deliberately take short non-disruptive breaks every half hour, and longer breaks every two or three hours.

It also involves making sure your tasks are broken down into things that can be done in small chunks - so you focus on the things that actually need doing, and avoid running away on a single problem.

There are plenty of similar techniques out there, which might vary in detail, but the key points of making sure problems are broken into discrete tasks which can be crossed off, and that you must take regular breaks, should help you to focus when you need to and move on when you might otherwise waste time down a rabbit hole.

  • Pretty cool, I was not aware of the pomodoro technique (et. al) Commented Oct 10, 2010 at 1:36

Train yourself to end at a specific time, and stick to it. Eg If you need to leave at 5pm, have an alarm that goes off at 4, 4:30, 4:45, and 4:55 warning you to just put it down and continue the next day.

The hard part of course is training yourself to do this. This mainly requires self discipline, but can also be helped by splitting up your work into units. The advantage of units is that you can complete a task quicker and get that satisfaction of completion earlier, which might give you enough sense to listen to that alarm going off. It will be tough, but its something that you've got to do.


Set yourself goals for the night. I get the impression from the answers that you basically sit down, start working, get into a flow and just keep going.

It's as much a time management problem as it is a self control problem - write down the things you're trying to achieve (nothing mental, don't bother with software, stick these tasks on post it notes, etc). Scribble an estimate against them - i.e. "Write feature X, should take an hour". Maybe even add a 'difficulty' score so you can get a feel for the potential problems you'll run into and how badly you'll fall into your flow and lose time.

Before you start working that evening work out how many hours you can spend and pick tasks that fit into that time slot - this is especially important (i.e. "I have two hours spare, i'm going to grab two 1 hour easy tasks, or a single 2 hour difficult task").

This is, in essence what I do now. I had a similar problem to you - in the end I realised that losing this time was a result of simply not anticipating problems or knowing the effort required for the task. As soon as I started thinking about this at the start and breaking my project down into really small little taks, it became much more manageable.

I will add a caveat to this though; Flow is a Good Thing (tm), and estimating is guessing - sometimes it just happens. What you're looking for a balance and managing your tasks better would give you this.

  • I think you hit the head of the nail which is my problem with this answer. Yes, I do basically just sit down, start coding, enter flow and off we go. But I don't manage my time even in the slightest. This has always prevented me from getting some coding done in those couple of hours to spare for fear of overshooting the time. Thinking about what to get done before starting solves this. And as a bonus, I get to practice estimating how long things actually take (never been good at guessing that). I shall take your advice to heart. Thanks a lot!
    – gablin
    Commented Oct 8, 2010 at 14:39

[I already have an answer to this question, which got roundly ignored point-wise. So I only stand to be ignored again...]

I've been thinking about this question today while I'm coding. For me, one the biggest reasons I don't want to put something down is that the transition costs are too high. I've got 5 terminal windows open, two or three servers open, etc., and plus I know what I'm doing.

To handle the terminal windows being open etc., I just sleep my machine, and most of the states are maintained. But as to knowing where you are and what you're doing...

One of the ways that MIGHT help you to stop when you're in-the-middle-of-something is to document where-you-are as-you-go. I pretty much do this now anyway, otherwise my ADD takes over: I always write the next 4 or 5 mini-tasks that I need to do, plus ANYTHING that I'm keeping in my short- or medium-term memory. This way, picking up the task the next day is easier.

So, by lowering the costs of stopping and restarting, you may be more motivated to stop. Or not, and this answer is off-base as well :)

  • Lowering the costs of stopping and restarting is useful, but I think I'd say that getting into restarting 'from fresh' is better than relying on things being in a certain state. Ideally your tasks should all be documented before you start on them, so all you need to note down when you stop is where you're currently at. (Though not necessarily bad to write down extra, once it's understandable.) Commented Oct 9, 2010 at 15:21
  • Having all your tasks documented before you start on them would be incredibly boring, and would stifle any creative impulse. But if it floats your bucket.
    – orbfish
    Commented Apr 10, 2011 at 4:16

Set an alarm clock to when you want to stop and decide if you want to continue crunching or call it a day.


It's clear that what's bothering you is having to wake up early in the morning and NOT staying up to the wee-hours of the night, nor missing lunch. Talk to your boss, wife, client, or whomever, and try to get some hours that respect your workaholic obsessive work binges. Assuming that you program effectively in those moments, who would want you to be balanced and "healthy" (big quotes around that: as if boring cycles are healthy)?

  • I, for one, want me to stay balanced and "healthy". I climb, swim and do weight training, so missing lunch, dinner and/or sleep is a problem.
    – gablin
    Commented Oct 7, 2010 at 9:32
  • @gablin, okay, point taken. THOSE motivations would be the starting point of a real answer, then: aside from using timers and such, you should figure out some way to keep your motivations present even when you are beginning to "flow." Commented Oct 7, 2010 at 12:47
  • Also, as I said: "assuming you program effectively in those moments" but you do not: as you said in another comment, "Furthermore, I find that I'm able to solve a problem much quicker if I'm allowed to step away from it and clear my head with something else." Knowing when to walk away is important... Commented Oct 7, 2010 at 12:50
  • @Yar: Yes, this is true, but when in flow I find it difficult to walk away. That is not to say that I enter flow only when facing a problem. In truth, the flow is only increased when I'm solving one problem after another, making great progress. What I meant to say was, whenever I face a problem when in flow, I often solve it faster by walking away for a little while if I can't solve it immediately. Being in flow when solving a problem often does me no benefit. But I should have phrased it better to make my point clear.
    – gablin
    Commented Oct 7, 2010 at 13:47
  • 1
    @gablin, I think that the real question that we're arriving at here is "How can I know when I've switched from Flow to OCD coding?" or something. I know what you mean: first you're jamming, then you're jamming on a different problem, and it goes and goes and goes and somehow you wind up at 4am having spent 2.5 hours banging your head against a problem that didn't really exist at all. And those last 2.5 hours could've been used to sleep. Commented Oct 7, 2010 at 18:01

Use technology to break you out of the flow.

For example, if you're using Windows 7, parental controls can lock you out of your account at specified times (meal times, bed time, etc). My suggestion would be to set up another installation of Windows (dual-boot) with all your development tools. Remove everything development related from your original Windows installation. On the development install, set up an administrator account with a long auto-generated password that you entrust with someone else (or put the password out of reach in some other way), and set up a limited account with parental controls which limit what hours you can use the account, so that during that time you're locked out of your account (locking the workstation doesn't close any applications, so there won't be any loss of work).

Getting the admin password to override the parental controls should be a long and inconvenient enough process to break you out of the flow, or a process that you won't consider doing at all (e.g. wake someone up late at night to ask for the password). As soon as you break out of it, hunger, thirst, and/or sleepiness will settle in, taking the place of adrenaline, and getting back into the flow will be pretty hard.

That's the general idea. I'm sure there are similar technological solutions you can try that will be more suitable for you (and that work on your preferred OS). I'm sure there are also solutions that require less work to set up, but I find that the less they require, the easier they are to bypass and the less chance they have of interrupting your flow.


I use Workrave to make sure I take breaks. I tend to get into the flow a lot as well and find myself not eating, sleeping, etc. Implementing a timing tool has helped tremendously. It is also good to step away from a problem sometimes. I've found my problem solving has improved since using Workrave. The breaks are good for the mind.

Not the answer you're looking for? Browse other questions tagged or ask your own question.