Monday, 13 September 2004

Tests allow you to be experimental

One thing that I love about unit tests is the fact that they allow you to be a bit experimental. There are parts of code that I understand why they were written in a certain way (I could have written them!) but I don't like it. They just have a bad, icky feeling about them. So I think of a new way to write the code, comment out the old code, play around, and as long as my new, cleaner, simpler solution passes all the tests, it gets checked in.

There is such a freedom that you feel when you have tests that you can't get without. I often wonder how other people (and me) programmed without having a test suite. How did we make changes? I still can't believe how simple unit tests are, and just how powerful they are. Crazy.
Listening to: Chicane - Saltwater Original


Update: Ryan had some excellent comments about this. I totally agree with the "if it an't broke, don't fix it" approach. In the case that I talked about above, it was because of a requirement change that I allowed myself to change the code, not because I felt like it. That's one thing that I find about XP: nothing is new or super "cutting edge", it seems to take a lot of best practises and common sense. But like a lot of other things, it becomes more than the sum of its parts. I can see that as being one of the road blocks for adopting XP, but that's another blog post altogether.

2 comments:

  1. Indeed, it's definitely a sum greater than its parts.
    Another problem is the value of some of the parts, like pair programming and developers using their time to test, is paradoxical unless taken in consideration of the whole of XP.
    If you think of pair programming as a waste of programmer resources, you are unlikely to look into XP further and discover it has many more long term benefits.
    While the sum being greater than its parts is a key asset of XP, it's also a big hurdle it its serious adoption.
    The good news is that you can slowly adopt some of the practises, like unit testing, without having to commit fully to XP. The bad news is that you'll never get a sum greater than its parts that way until you're doing complete XP. If some things are missing, the XP founders warn that your partial XP might not work too well.

    ReplyDelete
  2. That's one of the funny things when I read XP Explained. The author said "if you don't do everything and you fail, you can't blame XP". Okay, cool, that makes sense.
    Then he said you have to monitor the process too. If you don't change / tweak it for your env, it could fail and you can't blame XP either.
    It seemed like a CYA thing to me and made me laugh.

    ReplyDelete