Mental context switches are evil

This week I’ve run across two examples of technical strategies to reduce mental context switches.

The first example is Pete Kruckenberg’s story of why his team chose to develop a web application using node.js even though he had extensive experience in Perl/Apache. One of his arguments is that since the client-side code has to be written in JavaScript, it saves mental energy to use JavaScript for the server-side code as well. Even for someone who knows JavaScript and Perl well, it takes mental energy to oscillate between the two languages.

There’s much more to node.js than its use of JavaScript. It requires a very different approach to developing web applications. Kruckenberg and his colleagues had to weigh multiple factors in deciding their development framework. But it may not be too much of a simplification to say they chose a big, one-time mental context switch—the node.js style of development—in order to avoid countless daily context switches between JavaScript and Perl.

The second example is Ryan Barrett’s blog post Why I run shells inside Emacs.

Mental context switches are evil. Some people handle them better than others, but not me. I handle them worse. I feel it, almost physically, when context switches whittle down my precious flow piece by piece.

Barrett explains that he first tried configuring Emacs and his shell to be similar, but the very similarity made the context switch more irritating.

Even something as small as switching between Emacs and the shell can hurt, especially when I do it thousands of times a day. … What’s worse, only some parts are different, so my muscle memory is constantly seduced into a false sense of familiarity, only to have the rug yanked out from under it seconds later.

Both examples highlight the cost of context switches. Neither Kruckenberg nor Barrett mentioned the cost of learning two contexts. Instead both focused on the cost switching between two contexts. Novices might understandably want to avoid having to learn two similar tools, but these stories were from men who had learned two tools and wanted to avoid oscillating between them.

My favorite line from Barrett is “context switches whittle down my precious flow piece by piece.” I’ve felt little distractions erode my ability to concentrate but hadn’t expressed that feeling in words.

It’s no exaggeration to call flow “precious.” Productivity can easily vary by an order of magnitude depending on whether you’re in the zone. It may sound fussy to try to eliminate minor distractions, but if these distractions make it harder to get into the zone, they’re worth eliminating.

Related posts

13 thoughts on “Mental context switches are evil

  1. Jonathan Mugan

    Great post. Even something as simple as copying and pasting on a mac, then emacs, and later on a PC can really slow you down. And if the phone rings, forget it.

  2. There’s a huge literature on this in psychology: it’s called “task switching” and there are literally hundreds of papers about “switch costs”. What fascinates me is that we all have the subjective experiences you describe here, in which the costs of switching are very large and last for minutes or even hours; and yet the psychology literature typically finds that switch costs can be measured in milliseconds and that people reach plateau efficiency quickly. I wonder if there’s a way to properly study the experiences you describe in the lab.

  3. John: When I think of task switching, I think of larger changes than Barrett was discussing. For example, I’m working on a presentation and the phone rings. Now someone wants me to stop what I’m doing to help them with a program I wrote six years ago. That’s a very disruptive switch, one that could take a long time to recover from.

    I haven’t thought of it as a task switch when I’m preparing my presentation and I switch from entering text in slides to using a drawing program as long as it’s all for the same presentation. Changing software is a context switch, and it has a cost, but it’s less disruptive than the phone ringing.

    Maybe it’s hard for psychologists to set up experiments where people are interrupted from deep thought. They can give everyone an artificial puzzle to solve, but that’s not the same each person being engaged in his or her professional work.

  4. I’ve worked in an environment that has steadily grown more fractured over my ten years here. I feel that the demands to split attention between an in-flux of email, phone calls, IMs, and drop-bys, none of which I can systematically ignore, have not only eroded my productivity in the moment, but have taught my brain to expect distraction. I find it difficult in many situations, within and without work, to focus on any one thing or to plan to focus on any one thing. This leads to overlapping cycles of frustration and demotivation, which is tough to learn my way out of.

  5. I totally disagree that context switches affect productivity. Here’s a perfect example to illustrate my point. When I’m writing code I … one second someone is at the door. Ok, Like I was saying … hold on phone is ringing, gotta take this. Ok, so like I was saying, great article.

  6. Speaking of investigating deep states…

    Sometime in early graduate school – I think it was in a pedagogy course – we did an exercise where one person in each group talked their creative process out loud. In our group, a friend of mine wrote a fairly complex poem (might have been a ghazal) from scratch on the chalkboard, talking out his decision making process all the while.

    It was a highly useful exercise – not only to get a sort of common baseline for what other people’s internal processes are like (as best they can articulate them, at least…), but to see just *how much* a person *can* articulate of their internal mental states. Folks were working hard at this – talking about neuroses that they had, stray thoughts, the works.

  7. The main mental context switch here is between the client and the server side, not between the languages used here.

    I think there’s far more cost involved when you’re actually interrupted by someone with a ‘quick’ questions, a phone call,… compared to switching between languages. If you’re fluent in all languages involved, I really can’t imagine this to be a problem.

    In the past, I’ve often worked with rails and javascript at the same time. I think a lot of people do. I never felt this to be a problem.

    I’ve also worked on a project where I used ruby to generate a javascript file with php mixed in for the dynamic parts, and although it really demanded focus, it didn’t really bother me compared to an unexpected interruption.
    (and the javascript called a custom C server btw)
    When thinking about it, maybe the language differences even helped in this case to differentiate the separate layers in my mind.

    I like to use the right tool (language/framework) for the job. I think that using the same language only to avoid context switches would really be a mistake, unless it really just happens to be the right tool for the job.

    On the other hand, I’ve felt productivity hits when a project became too large and I was no longer able to keep the whole model in my mind. A really weird experience.

  8. I’m currently single-handedly implementing a webapp whose backend is in Python and whose frontend is a medley of HTML/CSS/JavaScript/jQuery. The context switches are many but I find them to be rather enjoyable and even working to my advantage. Here’s why:

    First, they don’t prevent me from getting into the zone. Rather they merely delay my getting into the zone.

    Second, I find that this delay creates a space of programming open-mindedness that is otherwise not there. Typically, when I’m in the zone I’m at my most productive but I’m also least likely to exploit a language feature that I don’t typically use. For me, a side-effect of being in the zone is that some sort of mental muscle memory is more likely to take control.

    Third, when context switching between languages I’m much more likely to view the syntax/semantic of the language I switched to in terms of the syntax/semantics of the language I switched from. I don’t mean to say that I assimilate the two languages (though I am probably less likely to write idiomatic code when context switching). I just mean to say that there is a certain beneficial critical mode that gets established.

  9. John,

    You reminded me of one of my favorite quotes from childhood. I’m pretty sure I saw it in a movie on TV, said by an old man, but I’ll be darned if I can locate it using Google. It went something like this:

    “I once knew a man who could speak sixteen languages, and couldn’t make a word of sense in any of them.”

  10. Here’s a relevant quote from Rich Hickey in an interview published yesterday.

    As programmers we’ve become quite familiar with many incidental complexities, but that doesn’t make them less complex, it just makes us more adept at overcoming them. But shouldn’t we be doing something more useful?

  11. I’m currently running a psychology experiment in the vein of the task switching literature. What has been previously found is that switching between more similar tasks produces less of a switch cost when making judgments. (For example, making a height judgment on a triangle is facilitated when you have make a height judgment on the trial before, as opposed to making a width judgment on the trial before).

    The question that I’m attempting to answer is whether this facilitation, or the task similarity effect, happens automatically without mental resources. If so, this could suggest that switching between anything, whether similar tasks or not, can use up precious mental resources that wouldn’t be engaged if one task was engaged in until completion.

    The most surprising thing I found when beginning this research was that there is really no such thing as “multi-tasking”. We can only switch between tasks and it might not really be efficient for us to do so.

    Great article – and I find the psychology research directly relevant to any work done using a computer.

  12. You can certainly learn to switch quickly between contexts. For example, I sometimes play sax and flute in pit orchestras. I’d sometimes have to switch instruments within a few seconds. There are three things you need to do to develop this ability.

    1. Practice sax.
    2. Practice flute.
    3. Practice switching between sax and flute.

    The third step is the easiest, but it’s not trivial.

    I know people who can speak English and French, but they cannot quickly switch between languages. No doubt they could, with practice, but the ability to switch quickly does not automatically come with fluency in the two languages separately.

Comments are closed.