You probably already know that when we switch tasks, we lose productivity. But today I want to tell you about a different kind of context switching, one that is hidden in the details, hurting your productivity even when you don't switch tasks.
Working Memory
Before we dive into micro-context switching, we need to understand how our memory works. We have different kinds of memory in our brains. The one we use when we are focused on something is called working memory. It allows us to hold contextual information about the task at hand.
Working memory is very volatile, mostly because it can hold a limited amount of information. When we switch tasks, we fill it with information about the new context, and the old context is lost. So, when we go back to the previous task, we need to spend time and energy restoring the previous context.
When programming, we keep the relevant code in our working memory, but it is really short-lived. We can only hold it for a short period of time. We recall words by a process called phonological loop, which can be interrupted by any minor distraction. Since code is made up of words, we rely on this process all the time.
Micro Context-Switching
When going to the kitchen for a snack, the context switch is obvious, but it is also possible to lose contextual information while you are coding.
If we are working on two related pieces of code at the same time, we need to be able to navigate through them in no time and without distractions. Otherwise, we risk loosing important contextual information.
We usually don't notice it, but micro context-switching happens all the time. I'll give you an example: you are debugging
When you finally find it, you lost some information about
The contextual memory is lost because we spent too much time doing a minor task like:
- scrolling a long file searching for a function
- browsing directories to find a file
- trying to find the right tab
- switching windows or apps
We can minimize that time in which we are distracted, by modifying the way we code/work:
- avoid extremely long files with hundreds of lines of code.
- spend time creating an intuitive folder structure
- keep the system architecture as simple as possible
- when working on two files, have them side by side in your screen
- use multiple screens to visualize different files/apps at the same time
- make sure that related methods in a class live together
- same thing for related functions
- use clear and descriptive names for variables and functions
Reflect and Refine Your Workflow
In the hustle of coding, it's easy to overlook the subtle disruptions that sneak into our workflow. Micro context-switching, those small distractions, can add up, affecting our productivity more than we realize. As we delve into the intricacies of code, we often lose fragments of context, interrupting the flow of our thoughts.
Whether it's programming, writing, or any other task that demands focus, take a moment to analyze your workflow and try to find the hidden disruptions stealing your attention.