From: Adam Sroka Date: 2005-12-22T12:28:10+09:00 Subject: Re: unit tests == ugly code? Joe Van Dyk wrote: > I've found that when I write the tests first, and then write the code, > I'm not very concerned about what the code looks like. When the code > passes the test, I drink a beer and party, then move on to the next > test. > > In practice, this means that I'm using a lot of ugly regex's, poorly > named variables, and so on. I'd be more concerned about the > readability of the code if there wasn't unit tests behind it. I'm > generally in a rush to finish whatever I'm doing, and figure that > since I have a bunch of tests, refactoring stuff later won't be a big > deal. > > Anyone else out there like me? Or should I be anal about writing good > code even with the tests? I guess that would be ideal, but I'd rather > get the functionality done first. > > Joe > You have to remember that TDD was popularized by eXtreme Programming, where it is combined with several other practices. There are few that really help. First, continuous integration ensures that all your tests are run frequently. Collective code ownership ensures that others on the team get to smell your funky code (And give you a hard time about it.) But, there are two that are really key: Merciless refactoring means that any time there is an opportunity to improve your code you take it. And, pair programming means that there is another person sitting next to you who is able to slap you silly when you code badly. You can do TDD without these other practices, but I'd advise that doing it without at least doing merciless refactoring and continuous integration is a little silly (But better than nothing.) Finally, if your code sucks you have no one to blame but yourself, and it's certainly not TDD's fault :-p