Feed on

TDD  changes everything. I’m reasonably comfortable you’ve already heard me write this, or imply it. So it’s perfectly natural to wonder — well, you know — How does TDD manage to change everything?

The answer is really the answers, because TDD, like most valuable techniques doesn’t actually work in just one single way. TDD is multifarious.

Here, then, is the first way: TDD reduces the mental scope of the developer.

Juggling Ideas For Fun And Profit

It’s been fifty-plus years since the famous paper by George Miller entitled The Magical Number Seven, Plus or Minus Two: Some Limits on our Capacity for Processing Information.

He identifies a first approximation of the bandwidth of human intellect. He says it’s about two and a half bits, i.e. somewhere between 5 and 9. By this number he means to refer to the number of independent concepts or symbols that a person can hold simultaneously. In fifty years, researchers have amplified and altered Miller’s actual number, but the long and the short of it is that we still think he was either outright correct or at least correct-ish. Five-to-nine works pretty well, actually.

I like to think of this five-to-nine with a juggling metaphor: some people can keep five ideas in the air at one time, and others can keep nine ideas in the air at one time, and most of us in between.

TDD Focuses The Mind

When I say that TDD reduces mental scope, I mean that it allows the developer to focus tightly on a single problem.

The experienced TDD-ist works one small problem at a time.

Working on just one problem works, because it obviates the need for thinking of the two other kinds of problem.

  1. Problems you (or a teammate) already solved.
  2. Problems you anticipate in the future.

Free’d by TDD to focus tightly, the developer is able to keep a problem to something involving less than our natural mental limits.

(Part of) TDD’s Magic: Reducing Scope

4 Responses to “How TDD Works Its Magic: Reducing Mental Scope”

  1. dyowee says:

    awesome… :)

  2. Philip Schwarz says:

    Back in 2008, in The Flawed Theory Behind Unit Testing, Michael Feathers said that quality is a function of thought and reflection, and that Unit testing (both TDD style or after development) does not improve quality just by catching errors: it does so by helping us achieve a state in which we are continuously engaging in precise thought and reflection.

    I agree with you that TDD frees me from the difficulties of juggling multiple balls at the same time: through divide and conquer it reduces the scope of the problem that I am dealing with at any one time to one whose scope is small enough that I can focus on it tightly because it does not stretch my mind to the limit.

    That focus allows me to continuously engage in the precise thought and reflection that result in quality.

    In your post, divide and conquer is used to break the problem down into smaller problems that are more easily tackled.

    This being the first of a series of posts, you likely will address another way in which TDD leverages divide and conquer. Martin Fowler describes it in his afterword to Kent Beck’s ‘Test Driven Development by Example’. He also uses a juggling metaphor, but he uses divide and conquer not to break the problem into smaller ones, but to break the act of programming into smaller elemental modes to achieve focus and reduce stress. Here is the gist of Fowler’s idea (I have turned excerpts of his afterword into bullet points):

    * Programming is hard.

    * It sometimes feels like trying to keep several balls in the air at once: any lapse of concentration and everything comes tumbling down.

    * TDD helps reduce this feeling, and results in rapid unhurriedness (really fast progress despite feeling unhurried).
    This is because working in a TDD development style gives you the sense of keeping just one ball in the air at once, so you can concentrate on that ball properly and do a really good job with it.

    * When you are trying to add some new functionality, you are not worried about what really makes a good design for this piece of function, you are just trying to get a test to pass as easily as possible.

    * When you switch to refactoring mode, you are not worried about adding some new function, you are just worried about getting the right design.

    * With both of these activities, you are just focused on one thing at a time, and as a result you can concentrate better on that one thing.

    * Adding features test-first and refactoring, are two monological flavours of programming.

    * A large part of making activities systematic is identifying core tasks and allowing us to concentrate on only one at a time.

    * An assembly line is a mind-numbing example of this – mind numbing because you always do the one thing.

    * Perhaps what test-driven development suggests is a way of breaking apart the act of programming into elemental modes, but avoiding the monotony by switching rapidly between those modes.

    * The combination of monological modes and switching gives you the benefits of focus and lowers the stress on the brain without the monotony of the assembly line.

    I look forward to your future posts in this series.

  3. […] well. The more advanced, sneaky design mechanisms behind it are covered (for the advanced reader) here and here and here and […]

  4. Mark Levison says:

    Great point, I had never looked at TDD that way. FWIW Miller’s experiment and discovery 7+/-2 is valid for numbers or small strings. But the larger the size the things we’re trying to remember the fewer we can handle. Since most software concepts are larger/more complex than numbers we want to reduce the number of concepts we’re carrying at any moment.

    A long winded way of saying you’re right.

    Mark Levison
    Agile Pain Relief Consulting

Leave a Reply

AWSOM Powered