TDD and the Senior Software Engineer
Many developers embrace test-driven development (TDD) as an ideal but rarely put it into practice. I often find myself writing code that works and then writing tests that exercise it to ensure that its behaviour doesn’t break when changes are made. Writing tests first is a great way to organize your approach to solving a problem, and in The Senior Software Engineer, David Copeland describes how TDD will help you grow your career as well.
A senior software engineer is efficient, and delivers a quality product in a timely fashion. Effective problem solvers first spend time understanding the problem space and then design a plan: documenting feature behaviour in a test suite allows you to plan your implementation. Code maintenance and modification are also more efficient when you have a good test suite. If the code has been built using TDD, its behaviour is already well tested. When someone needs to build on top of your feature, the tests will protect it and eliminate the worry of causing regressions (win-win).
Explicitly describing your plan in a test suite has another benefit that I had not considered before, and that is making you resilient to interruption. If your plan is not layed out on paper, you are maintaining it all in your head, and you have to hold on to a lot of context in your working memory. Every time you are interrupted, you have to dump things out of your working memory, and reloading the problem space takes time and energy. You won’t suffer interruptions well if reloading the context takes 15 minutes each time. You will become unresponsive as you block out the outside world, trying to maintain your context.
TDD can help you structure your coding task so that it has natural breaking points. If you are interrupted while trying to fix a failing test, you know exactly where you can pick the task up again. If you are interrupted after getting a test to pass you can easily read through your test suite to regain your context and pick up the next task.
Time and context management are essential skills for becoming a senior software engineer, and I am going to try using test driven development to become more interruptable and more productive.