What's it worth to me?

After you begin practicing TDD, or better BDD, for even a short while, it clicks. Once you get in the habit of thinking about the behavior you expect and describing that first in a test or spec, you realize there is a qualitative difference in how you are writing code. It’s not simply that you are writing code faster, or writing better code. You are working differently. A quantum leap, if you will. It’s a great, “Ah, hah!” experience.

I sketched a couple diagrams to try to describe this difference while chatting with Robby about creating shared meaning with clients. Check them out below.

Figure 1. Traditional linear perspective

Figure 2. Circular BDD perspective

The, seemingly, traditional view is linear. You start with no feature, do a bunch of whatever, and at the end you have the feature completed. The TDD/BDD view is quite different. Following the mantra—red, green, refactor—you start with a description of your expectations, you generate code that meets those expectations, and then you refactor. For all but the simplest bits of code, you will likely refactor numerous times. Refactoring is an explicit, purposeful, integral, regular part of creating code. And it’s not, typically, something you do to fix errors, which is how someone with a traditional view tends to understand refactoring. You refactor when your code is meeting your expectations (tests, specs) and those ensure that the product of your refactoring continues to meet your expectations. You refactor because the process of writing code changes how you are thinking about and understanding the code you write.

It’s difficult to find an analogue to this process in our everyday world. In construction, we would surely not build a room and then tear it down to rebuild it because our understanding changed. But an architect may well do that many times with a model in the attempt to create a solution that works. There’s no accurate, faithful way to transfer the architecture paradigm to software development. Many have tried, failed, and many will try again. Instead, BDD is an essential part of the software development paradigm and it’s processes should be understood, to some degree, by everyone participating in software development, clients included.

One significant challenge that we encounter is communicating the importance or value of a particular recommendation. There is more than conveying the information. We have experienced explaining to a client why it was necessary to refactor a particularly important part of an application. (In this case, it was more of a redesign, but since the behavior of the application was not intended to changed, we viewed it as a large scale refactoring.) The client acknowledged that our recommendation had technical merit, in some sense, but continued to view it as something of a diversion with little practical value. After all, the “features” were in place. We weren’t asserting that we would significantly change anything that the user interacted with. And the client was feeling the crunch of getting new features in front of the users.

So, the problem is much more than communicating information between developers and clients. It is essential to dialogue in a way that shared meaning evolves. The shared meaning brings our values into alignment. Then a true, rewarding process of collaboration powers the endeavor.

2 Responses to “What's it worth to me?”

  1. Gabe da Silveira Says:

    How much you can communicate really depends on the client. In the simplest terms I usually explain that doing something right now might take an extra 2 hours, but that it will save that amount of time every time the application is modified.

    Unfortunately this is a nebulous claim. All we can go on is experience. We’re trying to avoid unpleasant code maintenance situations we’ve been in before. To do our best we must pragmatize this desire, and honestly ask whether its necessary. If we do this well, we can be a trusted advisor for our clients. If we don’t, well, then we’re just another perfectionist programmer with a feature list 10 times the size of the budget.

    That said, I’m not on the TDD / BDD bandwagon yet. Maybe I haven’t made the mental leap. I’ve done it a few times, and I am writing decent tests (in Rails anyway), but in some cases I’m still finding the type/save/reload to offer greater feedback than a blackbox test.

    Putting methodologies aside for a second, I’ve found tests to be most useful in maintenance. Not just as a refactoring tool, but as plain old documentation. A basic set of well-written tests (at least with a testing environment as simple as Rails) tells me more about the code than the code itself does in some sense. I guess because each test is focused and describes a quality of the outcome. Whereas the code often contain subtle bugs that are not easily identifiabled (bug or bug fix?), tests are typically self-evident.

    What this all boils down to for me, is that tests codify the expectations of the programmer. That’s maybe why I haven’t jumped headlong into TDD yet—I already have tests in my head as I’m coding. The real value of tests is saving those thoughts for posterity. I (or someone else) can come back and immediately get back up to speed without mental code traces.

  2. donald Says:
    It’s difficult to find an analogue to this process in our everyday world.

    I don’t know about that. It strikes me that test-driven refactoring is analogous to the process of evolution. Something to think about, anyway.

Sorry, comments are closed for this article.