13 April 2005

TDD continued

Now my new calculator is working I have 18 tests and they all pass. I have deliberately not thought about the design too much.

There is quite a bit of duplication in the code. I'm tidying it up. It's almost refactoring, but as there is only one little class, really it's just reviewing the software as a whole. Up till now I'd been looking at just the functionality I was adding to satisfy each new test. This lead to a working program, but not one that I'd be proud to display.

To start with I moved any common code into new methods and then recompiled and ran my tests. Occasionally this warned me that I was introducing a bug and I was able to roll back and see that indeed the tests were right and it was not quite common code after all.

Then I reviewed the names I'd used. Some of them were pretty vague so I gave each method property or variable a meaningful name. The tests confirmed everything still worked.

What I plan to do now is to work on something else for a week or so, then come back to this project and try to add some more functionality. Perhaps I'll add some memory keys. The idea is that the tests should make it easy to continue development.

I added some comments as I was coding, but now I have removed these. The theory is that you don't need comments if you have unit tests and readable code. We shall see...

No comments: