I was reading through many of the recent posts on the harmfulness of multi-tasking this weekend.
Many cite the cost of a push/pop operation as harmful to multi-tasking. This can absolutely be the case. Some things are very costly to push/pop other things are not costly to push/pop. I feel however the discussion is being completely lost. The issue is not that we should avoid multi-tasking at all costs. We should be trying to figure out what things are low cost to push/pop and what things are high cost to push/pop.
Imagine for example that I asked you to write two programs with TDD. The first is FizzBuzz, the second is to count the recurrence of words in a text. In a quick non-scientific example I was about 10% less productive working on both at the same time (with switches between them at +- 3 minutes) than I was working on each separately start to finish (there was a mild cost of push/pop). I think I could have gotten them to near identical time if I had made my switches allowed 15 seconds or so to find a stopping point (I literally stopped typing in the middle of a word and alt-tab’ed).
In another quick non-scientific study I tried with simple features in a much larger space (e.g. adding features into a larger more complicated code base). I was in this case much slower. The reason why was that my push/pop costs were much higher. I was keeping more information in my head and it took me longer to get back into the problem.
Disclaimer, I often like to think I am multi-tasking. I often have 2-3 things going on the “back burner” where suddenly thoughts hit me and I mark down that thought and continue with what I was working on. How often do you solve that difficult bug while in the shower or cooking spaghetti?
However I see the difficulty of multi-tasking in a code base to be just like any other “ility” it is something that we can optimize towards (and likely we are making tradeoffs on other things). In particular coupling and complexity come to mind as related to the ility and I don’t necessarily mean cyclomatic complexity when I say complexity (it is often more difficult to work in very highly factored code where to put together an operation you need to bring together 20 well factored pieces that to look at one piece of code with high cyclomatic complexity). Oddly these same things that slow you down multi-tasking are the same things that slow down someone new to your team that needs to ramp up.
If you are writing code that you lose exponential productivity in multi-tasking with its probably because the code is complex. Your push/pop costs are high. You probably have a lot of other issues with this code like bringing new people into it.
If something is difficult, do it more.
The best way to get through such problems is to do it more. You are hurting due to complexity and push/pop costs? Multi-task more, where does it hurt when you are multi-tasking? Some tasks are truly complex but more often than not we introduce the complexity ourselves. Our models are wrong.