The Inquisitive Coder - Davy Brion’s Blog

Trying to walk that thin line between intelligence and ignorance

Is Teaching TDD Worth It?

Posted by Davy Brion on September 21st, 2008

There’s a debate going on the ALT.NET mailinglist about whether or not teaching developers TDD for a project is worth the cost. I don’t really like the way things are discussed on that list nowadays, so i’m posting my thoughts here.

First of all, it’s definitely true that learning how to do TDD effectively takes some time and the learning curve is rather steep. If you need to bring people who are new to it up to speed, you definitely have to invest some time in that. So, is the time and effort spent on that worth it? I think it most definitely is. If you take the time to teach them how to do it properly, you can enjoy quite a few benefits.

For starters, the developers will improve their skills, not only in writing tests, but also in writing flexible and simple code. This can take some time, but if you’re coaching them properly you should get this situation under control in a couple of weeks (somewhere between 2 and 4 weeks depending on the number of developers that need to be coached, and their general skill level). The quality of the code (and the tests) that they’ll produce after this period can reduce your total future workload by a large quantity. I think most of us know what it’s like to work with code that is anything but flexible, and what a negative impact such a situation can have on your team’s productivity: things that should be easy to change, features that should be easy to add can become mind numbingly complex to implement without introducing bugs to existing code. I’ll gladly coach a few developers for a few weeks if that means avoiding a code base where people are afraid to make changes or where change in general is lengthy and painful.

Also, during this period where you have to do intensive coaching, you can still make progress in the project. It’s not like these developers have to learn these practices and principles on throwaway code. Have them work on real stories for the project. Double the estimates for those stories, and don’t assign any stories to the person(s) doing the coaching. Make sure they have enough room to help the developers that need the help and that the code (and the tests) are up to standards before the stories are considered done. If you’re coaching them right, you might be surprised how fast they’ll pick up the pace. You’ll definitely take a large productivity hit in the first couple of weeks, but after that your team’s productivity will go up rather fast and before you know it, you’ll have made up for all the lost time and with a healthy code base to boot.

Now imagine not investing that time and effort. Without even thinking about who’s going to write the tests, or when they’ll be written, suppose you decide not to spend the time and effort to teach them TDD. You start the project and everyone starts implementing features. Some people will write good, solid, flexible code. And some people won’t. Their code might stay in this unhealthy condition, or it might deteriorate further. But hey, your team’s productivity in the first couple of weeks sure is impressive right? Fast forward a month or two, then tell me how the productivity of your team is. It probably won’t be as high as it was in the first couple of weeks. Oh, and keep an eye on team moral. Chances are that some developers will be terribly frustrated by some of their teammates’ inability to write good code. The rest of the developers might be frustrated because some developers are too demanding and bitch too much about how bad their code is. All in all, chances are high that it’s not going to be a fun team to work on.

Now, as for the teaching and the coaching… this can be a relatively easy job, or it can be a royal pain in the ass. It all starts with the developers’ willingness to learn. If they are not willing, get rid of them. Yes really, get rid of them. You’re only doing them, yourself and the rest of your teammates and your organization a disservice by keeping them on staff. If they are willing to learn, make sure that they realize that you are there to help them. If they are afraid or hesitant to ask questions, then you are definitely doing something wrong. They have to be certain that you will do the best you can to help them, and that they won’t get ridiculed if they ask stupid questions. And let’s face it, we all asked ’stupid’ questions when we were learning these things so you sure as hell shouldn’t make another developer feel bad when he/she is in the same position you were a few years ago. Also, when they do good, make sure you reward them by showing them more trust. You’d be amazed what kind of a positive effect that can have on a developer who’s trying to learn a new approach. And never ever simply tell them what to do and what not to do. Make sure you explain everything! If they see you’re taking the time to make sure they understand why you’ve given the advice that you’ve given, they will usually appreciate it and they will certainly learn a lot more than they would’ve if you had simply told them not to do something.

All in all, deciding against teaching people TDD is one of the worst decisions one could make IMHO. It may not always be fun and it may not always be easy, but in the long term, the quality of your project will benefit greatly from it. If teaching them TDD is painful, then you’re either not doing it right, or you’re working with people you probably shouldn’t be working with anyway. But teaching TDD is generally not hard, as long as one party is willing to really teach, and one party is willing to really learn.

Share/Save/Bookmark

9 Responses to “Is Teaching TDD Worth It?”

  1. Dew Drop - September 22, 2008 | Alvin Ashcraft's Morning Dew Says:

    [...] Is Teaching TDD Worth It? (Davy Brion) [...]

  2. Arjan`s World » LINKBLOG for September 22, 2008 Says:

    [...] Is Teaching TDD Worth It? - Davy Brion ‘ There’s a debate going on the ALT.NET mailinglist about whether or not teaching developers TDD for a project is worth the cost ‘ Man, I’m missing out on interesting stuff! On the other hand - as Davy himself mentions - a lot of potentially interesting stuff is discussed over there, but you have to seperate the wheat from the chaff, which just costs me too much time [...]

  3. Colin Jack Says:

    Great stuff.

  4. What Lao Tse thinks of TDD | The Freak Parade Says:

    [...] once more and sinking back into the carpet, and the usual band of roaming ALT.NET monks came to the vigorous defense of TDD, which was apparently issued a challenge on the ALT.NET mailing list. All this in [...]

  5. Dale Smith Says:

    Hi Davy,

    Couldn’t agree with you more. I work in a large(ish) development group (50+) with mostly .NET dudes, in the context of a command-and-control organization. Like many .NET shops, management has approached hiring, training, and project management practices with a mentality - one dev is as good as another, if it’s not from Microsoft it can’t be any good, etc. This has lead to some spectacularly bad legacy code.

    To combat it, a small group of devs in our shop have been promoting TDD. We started with CI - I figure that developer testing is ALWAYS worth it, but you get so much more out of it in a team situation when you pair it with CI. Once we got underway with CI, we started adding tests as we had time, off-book, working a little extra when we had to. Over time, Management slowly recognized the value of developer testing, and has now begun to insist that developer testing be part of our project plans.

    We still have a long way to go in addressing all our legacy code, but I can see lots of progress, both in the code base and in our development shop’s skill level. One of our most talented developers told me that he achieved his largest leap forward in skill level, particularly in design skills, by learning how to make code testable.

    The biggest thing I’ve had to remember is not to expect immediate adoption of 100% of my agenda. I have to be satisfied with 2% incremental progress at a time. I’ve begun to think of our TDD skills and practices as a kind of technical debt carried by the group: we’ve made progress, and there are some things we have to compromise on in this iteration in order to achieve a deadline, but we’ll take care of those things in a future iteration. As long as we’re not going backwards, any progress in developer testing is ALWAYS worth it.

  6. Davy Brion Says:

    @Dale

    interesting stuff :)

    and i definitely agree that you can’t expect immediate adoption of your entire (technical) agenda… i prefer to increase that adoption on a steady basis, but to take small steps while doing so. It just works better, for everyone involved actually :)

  7. Incognito Says:

    Great post Davy! Looks like you would be a great TDD-coach!

    Obviously, the best thing is to have someone around that is a TDD-master and can guide you in any mistakes you make, explaining what’s wrong and what would be better, and why that would be better anyway…

    But what to do with developers (such as me) who are eager to learn, apply and master TDD, but don’t have any coach? Do you think it’s possible to “selfstudy” TDD? Any suggestions on how to handle that?

  8. Davy Brion Says:

    i acquired most of my TDD experience on my own, so it’s definitely possible. It does take a while though and it’s not always easy.

    The best way to start learning it on your own is to read Kent Beck’s Test Driven Development By Example… the examples may not be representative of the code you’re going to write, but it definitely teaches you the whole TDD mindstate. I’d also recommend the book xUnit Test Patterns.

    And then you just need to start experimenting with it, and stick with it, even when it gets hard (and it surely will at first). But the important thing is to just ‘listen to the code’. If TDD hurts, you’re not doing it quite right yet and you need to investigate better options :)

  9. Alexander Byndyu Says:

    Very interesting thoughts.

    [...]For starters, the developers will improve their skills, not only in writing tests, but also in writing flexible and simple code. [...]

    I was talking about it approximate 6 month in my company =)

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>