The title is a line from an episode of Uncle Bob’s clean code video series. He advocates refactoring until you get down to 3 lines of code per function and make sure every function is doing one thing and is clearly named. At least that’s what I got out of it. I like his approach on this. So part of Test Driven Development in the coding to make the test pass phase is to do whatever is simplest and easiest to get the test to pass. Well, maybe with some caveats, although I’m not sure what they are right at the moment, but I’ll let you know as I think of them.
So, what did I write that I want to refactor? This:
I don’t like this giant if else set of structures I added to this function. So what can I do? How about extracting the boolean tests to some functions…
Ok, so the original BeforeUpdate module is now SUPER clean. It checks the function FieldChanged, passing the field and it looks much nicer. I’ve now moved most of the code into it’s own function. Before continuing to refactor, let’s make sure I didn’t break anything by running the tests:

Yay, so I think I can make the new function FieldChanged much cleaner as well. Let’s see:
Well, it’s getting better, but I need to do more. Tomorrow… Thanks for joining me!