September 27th, 2006


Coders Anonymous

We use Rule objects to determine whether a Control is valid or not. You assign 0 or more Rules to that Control and then it checks all of them whenever the Control is changed.

I had to write my first rule today. I discovered that the bit of code that is run to check whether the rule is valid is about 5 lines of code that's identical in every rule, the actual checking code, and then between 5 and 15 lines of code that varies depending on the number of controls a rule needs to inform when it's changed.

I had two rules to write. There was no way I was going to copy and paste code _twice_. Far too much like hard work.

3 hours later I've refactored all 40-odd existing rules to use a new way of working that runs those 5 lines of code, then calls into a separate method to call the actual validation code, and then works out what Controls to inform dynamically.

Yup - I spent 3 hours avoiding spending 45 seconds copying code. Because frankly the thought of having to do the same thing twice (with a vision of many more copy/pastes to come) drove me insane.

I wonder if there's a self-help group I can join.