TDD – Path to code Zen

tdd-red-refactor-greenTest Driven Development has many advantages, but there is one that I discovered the other day: it helps create order in the chaos that can be your own brain and it helps keep track of the progress you’ve made in implementing a complex algorithm.

The story
I was working a complicated algorithm. Doing well, I had about 30 different scenarios that needed to be supported, all organized in my brain. Coding, coding, coding… This is probably a 6-8 hour job and I’m about half way done. Phone rings, I get drawn into a DevOps issue. Done, time to get back into code Zen, not easy, but almost back in, phone rings again.
This happens two more times, and then I’ve lost it. Unable to get back into the code Zen. The scenarios just don’t want to line back up in my brain. After 30 minutes of trying, of attempting to code, no real luck. I give up, knowing that if I start fresh in the morning I can get back into Zen… until of course the first call comes in.

Next morning I decide I need to apply TDD. Build my unit tests, take the implementation one scenario at a time. And it is working! The phone still rings, but in order to achieve code Zen I only need to get back into the one scenario I was working on when the phone rang. Much easier than organizing my brain around the 30+ scenarios that I had to keep track of before.

Win for TDD.

Happy coding.