andrewducker: (Default)
[personal profile] andrewducker
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.

October 2025

S M T W T F S
    1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31 

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Nov. 1st, 2025 09:19 am
Powered by Dreamwidth Studios