Exploring Existence

TDD or Test-Last? One Thing at a Time

Programming is a challenging activity. One major cause for this is the sheer amount of balls to keep in the air. At any given time, we need to:

I used to work this way - dealing with all these concerns simultaneously. It made me feel like I was drowning in complexity and often overwhelmed. It was unenjoyable. At some point, I almost accepted this - apparently, this is what it means to be programming.

tld-cognitive-load Cognitive Load when programming

Thankfully, it doesn't have to be. We can disentangle these concerns and face them one at a time.

Disentangling Programming Concerns

At first glance, all the activities I mentioned seem inseparable, like a big blob of spaghetti code. But if you look closer, from a different angle, you start to see fault lines where the activities can be separated. Programming starts to look like distinct activities:

Following this insight, it makes sense to separate the activities. That is precisely what TDD helps with.

TDD to Separate Concerns

At the core of TDD is its mantra: red, green, refactor. You go from one phase to the next in tiny iterations on a scale of mere seconds or minutes. Each phase forces us to look at the problem "wearing a different hat."

I like to explain the cycle like this:

first, make sure we build the right thing, then build the thing, and lastly, build the thing right.

tdd-cognitive-load ‌Cognitive load is reduced by separating activities

As you can see, these distinct phases have different goals. Instead of "juggling" all three concerns simultaneously, TDD strongly nudges us towards delineating them in a sequence of steps. It's like moving from keeping three balls in the air to just one while simply holding the remaining ones in hand.

Conclusion

Do you need TDD to do this?

Not necessarily, but like I mentioned previously, TDD does nudge you in the right direction.

TDD can help to separate concerns in the act of programming. It has helped me do so, and made coding a more enjoyable experience in the process. It drastically lowered the cognitive load I had to deal with. TDD permanently changed how I see the act of programming - distinct concerns to cycle through.

#TDD #complexity #tech