Friday 16 November 2007

1 UI Control, 73 Unit Tests

When you start introducing dependencies into things, they get complicated pretty quick.
This is doubly true with validation: if one value relies on another, then you need to validate both inputs when either of them change.
If A and B depend on each other, and B and C depend on each other, then you get into really deep water.
The way I've dealt with this is by using a "propagate" flag in the validation functions, which determines whether something should call validation on its dependents.
It seems to work pretty well, but I can see this getting grizzly when theres more than one thing going on. It does help isolate each validation function to be able to validate one thing at a time.
Also, doing it test driven has helped - towards the end, the cycle was only hindered by the speed of compilation.
I'm now confident that it's a robust control that I can build other parts of the UI around.
I think using some kind microcontroller may have helped break it up a bit mind, but that's a refactoring for another day.