I was coding something in G4 recently, and it was in theory a simple thing. I was trying to work out why a certain unit in my game was not opening fire on another unit when I knew it should be.

When I was looking at the unit onscreen, it was one of several, and stepping through code is frustrating if you aren’t sure who is who. The best solution in this case was for me to overlay a range UI on the screen so I could check it wasn’t a range issue. That meant writing some new code to display the range UI, which is fine. The problem is that meant getting the range for that unit into the GUI code, and there was no simple way to do that yet. That meant writing some new code to make a note of the range for that unit elsewhere…

In an office, this is normally the point where someone taps you on the shoulder or asks you a question… And then it all falls apart. At this point my mental ‘stack’ is this:

Working on G4
...Debugging the firing bug
...Adding a range overlay
...Writing code to access max range

The longer that list gets, the longer it takes to get back into what you are doing. With really bad bugs (I coded a neural newtork once…eeeek) you can be 10-15 layers in. It can take a good 15 minutes to mentally rebuild that stack accurately if it gets lost, and it *will* get lost the moment you lose your train of thought.

Short summary: Make sure nobody interrupts you when you are coding.

13 Responses to “The mental coding stack, and avoiding interruptions”

  1. Drealmer says:

    And it is amazing how hard it can be to explain that principle to non-programmers.

  2. I always have a text file open in which I type whatever I have in mind related to a specific “stack”. Takes more time if you are not interrupted but if you are you just saved some minutes with this text stack. At least I have many times.

    Nothing fancy. Just some words that pops back the proper thought.

  3. BuschnicK says:

    Make sure you don’t interrupt yourself and give in to the constant siren song of email/twitter/hackernews/slashdot/stackoverflow/ICQ/IRC…

  4. Informis says:

    I loved “The Social Network” for a lot of reasons, but there were several scenes in it where developers warned off non-developers from interrupting someone by saying “No, don’t. He’s wired in.” I wanted to cheer, every time.

  5. radio_babylon says:

    as a programmer ive developed a really handy skill, wherein i am able to make eye contact with whoever is interrupting me, apply one of 3 or 4 generic facial expressions appropriate to whatever is being said, and even speak (although only a few words, like “yes” and “no” and “ok” and “maybe”)… all while i continue typing on whatever im working on. everything needed to provide a surface illusion of actually paying attention… when in fact, i heard NOTHING that was said to me, and 99% of the time have NO recollection whatsoever that anyone ever even came into my office.

    my bosses/coworkers have learned to ensure that i have not only STOPPED all typing, but that i can intelligently answer a complex question, indicating that they have successfully yanked me out of my workflow and destroyed all my productivity before they even begin to babble on about whatever stupid fucking thing i dont care about that they came in there for in the first place.

    what i WISH they would learn is to LEAVE ME ALONE WHILE IM WORKING instead of finding more effective ways to ruin my flow.

    lol it hasnt even happened today and now im already raging about it. just *thinking* about it happening drives me crazy…

  6. I now whiteboard or notepad this kinda thing so I don’t have to throw “shut up!” and “not now…” at family. :(

  7. CountVlad says:

    If I get interrupted when I’m doing something horribly complex I generally tend to half-listen to what is being said while keeping the thought ticking over in my mind somehow. Fortunately my family seems to have learned that if I look like I’m doing some really complicated piece of programming (i.e. lots of seemingly random text on the screen) then I probably am!
    Also, writing things down helps… though I tend to use that more for a long-term to-do list.

  8. gunny says:

    uh…. question….

    what’s G4?

  9. I’m not a programmer, but I think the same situation occurs in all sorts of nested problems requiring a similar “flow” of thought.

    It’s not necessarily just one task leading to another leading to another, either; it can also be interwoven tasks that can only be performed by working a little on one, then the next while keeping the first in mind, then another, then maybe the first one again, et cetera.

    I think of it as as “juggling plates”. When you’ve got several “plates in the air”, you may not be able to save ANY of the crockery if you suddenly lose your juggling rhythm, for whatever reason.

  10. Gregory Fahey says:

    Soooo… G4 has units and shooting in it?

  11. kone says:

    That’s the spirit, Greg!

    Maybe you also successfully guessed the title of G4.

    “G4 – units and shooting.” (one might want to append a “, Bitch!” at the end :-) ).

  12. Andy says:

    “Short summary: Make sure nobody interrupts you when you are coding.”

    Sadly this is all too true. At one former workplace the interruptions got so bad during crunch that I took a piece of A4 and scribbled “F@#k OFF!” on it, then stuck it to my head/hair with blu-tack. Every hour I’d take it off for 5minutes until I’d got list of work items that would keep my busy then re-attach the sign.

    Sometimes people just don’t realise how often you’re being disturbed or that the disturbances can be coming from multiple people.

  13. Alex says:

    Well said Cliff

    I mentioned your post in my article about “JavaScript and mental stack” here:

    http://blog.diagramo.com/2011/01/javascript-and-mental-stack.html