I've been thinking about why I didn't do Test-Driven Development for so many years (in particular, writing tests first), and why others don't.
You can be shown lots of books. You can be told it's important. But you still don't do it.
I think it's about discomfort. You're being asked to change. For years, the way I coded was: I did some analysis, thought about the design, and then started coding the design as I saw it, either from my head or from some basic UML.
TDD doesn't let you do that. You have to (ick) write a test first. Why on Earth would I ever want to do that? I'm trying to implement my design, not muck around with tests! So as much as I appreciated from afar the values of TDD, I just never get around to doing it, because it's just not how I did things. It's almost like you're coding naked or with a keyboard with a different layout - it's awkward, uncomfortable, and just feels wrong.
So I came up with all sorts of justifications for not doing it - I don't have time; I'm already writing tests, writing them first seems like overkill; I'm already overwhelmed with things I need to deal with; people who that are just anal design-freaks, and so on. But I think ultimately it came down to - that's just not how I do things.
But recently I finally forced myself to start doing it. I slowly started becoming more comfortable with this approach, and started to see the benefits.
To me the key thing is this concept of letting the design emerge rather than trying to impose a design. It's similar to starting with use cases first, and regularly validating your product with the customer, rather than building a technology and hoping they'll come.
Once I got used to letting the design emerge, I started really enjoying TDD. It was an act of discovery as much as an act of creation. And I truly believe the best creations are done that way - as an act of joyous discovery.
And yes, by the way, you get much better code coverage when you do TDD, because you ensure that each "piece" you build is tested, rather than writing a bunch of code and then trying to figure out how to test it.
And yes, by the way, you get designs that are much less coupled and more cohesive.
But to me my favorite part of it is that joyous process of discovery.
1 comment:
+1 In a way, it reminds me of sculpture. Some artists talk about starting with a block of marble and uncovering what is hidden within.
Post a Comment