TDD: The Vegetarian at the Party

There’s a joke that asks “How do you find a vegetarian at a dinner party? Don’t worry, they’ll let you know.” This past week I’ve thought about how, to a large extent, that’s true about TDD practitioners as well. If you’re wondering who in your community or office or friends writes code using TDD, you don’t have to worry, they’ll tell you.

This lead me to wonder if there are other parallels between TDD and vegetables and I found a few.  First, eating vegetables is much harder than eating junk. I used to have almost an addiction to fast food, I enjoyed it. I knew it wasn’t good for me, but the ease of hitting a drive through and having something that tasted ok and didn’t cost a lot of money was just too much. Should I have gone home and ate some vegetables instead? Absolutely, but did I? Not as often as I should have.  TDD is a lot like this. It’s so much easier to think “I can just create this form, it’s not that hard” or “I’ve done authentication a ton of times, let me just whip that up real quick.” The problem is, however, just because something is quick and easy doesn’t mean it’s right. Sometimes we have to fight against our nature to do what is right, instead of what is easy.

Secondly, a steady diet of junk food leaves your body in bad shape. Over the past 12-18 months I’ve started taking my health more serious. I’ve exercised more and pushed myself physically. After doing that for a little bit, I realized that I needed to adjust my diet as well. As the saying goes, “You can’t out train your fork.”  (I’ll be honest here, I’m still not on a very good diet, but it is quite a bit better than what it was.) What I found during this time is that it was hard to see changes physically. It was hard to not feel completely miserable after a rough week of training. Why? Because for most of my adult life I hadn’t really been eating that well. I’d been putting junk into my body and now expecting it to perform like a well oiled machine. My friends and teammates who didn’t go through a “junk food phase” have a much easier time maintaining a good weight and diet.  The same is true with our code. If we continue to choose the easy way, the junk food way, of just trying to get stuff done as fast as humanly possible, replacing quality with speed, our projects are going to in a bad spot.

When I first started training, I experienced physical debt. The debt of too much time on the computer, not enough time off my  butt. The debt of too much junk in, not enough good food.  It meant I was sluggish. With our code, we call it “technical debt” but really, that is just a fancy way of saying “We were doing things we shouldn’t have been doing in the first place.”  The library you have that is so fragile that every time you touch it, it breaks, or the the application that is so full of spaghetti code that nobody wants to work on it. Both of those are a direct result of having a steady diet of junk food (bad coding) and not eating enough vegetables (TDD.)

The third way that I saw TDD parallel vegetables is that I’ve yet to find someone who said vegetables are bad for you.  Sure, I’ve met plenty of people who say vegetables taste bad (I have lead that charge myself), but I can’t remember the last person that told me that they were actually bad for you.  So too with TDD. Very few people argue that it’s bad to do TDD. Almost everyone I’ve ever talked to agrees that testing is good, that clean code (a by product of TDD) is good. The problem becomes that there are numerous objections that don’t have to do with TDD being good or bad, but other factors. For example, will it slow us down? Won’t I be writing more code? How do you test GUIs? The list goes on and on. In the end, they answers sound a lot like me objecting to eating more vegetables. They don’t taste good, they take too long to cook, I can’t get them in a drive-thru.  In fact, at one job we went to a new gourmet pizza place and the boss ordered the table a brussel sprouts appetizer. If I remember right, it was bacon and brussel sprouts. I didn’t eat any, and I was asked by the boss’ wife if I was a vegetarian. I thought about replying “Just the opposite, the sprouts are ruining the bacon.”

The problem is, none of my objections really dealt with the root cause. I wasn’t eating healthy. I can’t fill out a life insurance policy with slightly elevated blood pressure and say “But vegetables don’t taste good.”  I can’t not go outside and play with my kids by saying “I really wanted to eat a bunch of Swiss Cake Rolls today.”  By reasons for not eating vegetables weren’t weighty enough. And so too objections to TDD.

So to paraphrase the opening joke, “How do you find a TDD developer at a conference? Don’t worry, they’ll let you know.” TDD is a lot like eating vegetables. It takes some getting used to. It’s not as quick and easy as just slamming some code in the IDE, but in the end, your project and your team will be much happier if you write code doing TDD, than if you constantly hit the drive-thru of software development.


Leave a Reply

Your email address will not be published. Required fields are marked *