Sep. 27th, 2006

andrewducker: (Default)
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.

August 2025

S M T W T F S
      1 2
3 4 5 6 7 8 9
10 11 12 13141516
17181920212223
24252627282930
31      

Most Popular Tags

Page Summary

Style Credit

Expand Cut Tags

No cut tags
Page generated Aug. 15th, 2025 10:18 am
Powered by Dreamwidth Studios