TDD & Flow
In the “flow” (or, in the “zone”) is the state where you can do your best and most productive work.
According to psychologist Mihaly Csikszentmihalyi, the following three conditions are required for flow (being in the zone):
1. One must be involved in an activity with a clear set of goals and progress. This adds direction and structure to the task.
2. The task at hand must have clear and immediate feedback. This helps the person negotiate any changing demands and allows them to adjust their performance to maintain the flow state.
3. One must have a good balance between the perceived challenges of the task at hand and their own perceived skills. One must have confidence in one’s ability to complete the task at hand.
I came across above while reading the book The Art of Finding Flow by Daman Zahariades. It made me think how TDD (Test Driven Development) enables above three conditions to be fulfilled and perhaps why it improves productivity as well as quality of the work (Remember, TDD is not a testing technique, it is a design technique).
1. Clear Objectives
In TDD, we write a failing test first. This makes our objective very clear - to make the minimal changes which gets to make the test pass. Progress is also easy to measure.
2. Fast Feedback
For any change made, you get immediate feedback about whether it is making test pass or fail. E.g. I use entr which keeps on running compile + test on every file save I do. Thus, I get instantaneous feedback on whether I am moving in the right direction or not.
3. Confidence
Given a failing test, I would think that hardly any software engineer would feel under-confident to be able to fix that. Problem solving is what we all like and thus, having a reproducible failure enables us to focus our attention on fixing it.