This is part 2 of Hack Your Brain to be a Better Developer, my talk from AdieCon 2020.
You’re writing tests. You’ve got a mental map of how pieces of code work with each other, and an idea of what structures you’re going to set up for the test. You make mental note to change this var to that var. Then you realize you need to look something up, there’s a meeting, or the service you run tests through is suddenly down. You address the issue/attend the meeting, and switch back. Wait, what were you doing again?
The work we as developers is working memory intensive - make and track connections, update ideas, and task-switch. Memory research shows these tasks use the same WMC - working memory capacity, and we all know what happens when more memory is required than what is available:
Brain Stack Overflow
So aside from avoiding interruption, what can we do? I’ve tried a bunch of things and the best solution I’ve come across is to keep a timestamped diary. Note the time, what I’m working on, where in the code I’m working, and why I’m doing it. When my working memory capacity is hijaked by something else I’ve got a log to reference.
I also find this helpful for validating how much time tasks are taking, so I can keep at something that’s difficult but I haven’t actually been at that long, or pivot to a new tactic when the log shows I’ve been at it for a while.