Thursday, August 4, 2011

Keep Business Rules Legible in Your Code

I've just realized that this is one of my driving "code philosophies" though I've never really put it in words. It drives me to write code that separates the DML from the business related code. I understand that in some instances, this can lead to code that is slower than it could be.

Additionally, I strive to code one rule at a time, where possible. This allows you to test and debug a single rule, isolated from the rest of the mess.

However, I have seen that it leads to code that is reusable and more reliable than when you write code that contains everything in one SELECT statement. When you jumble multiple business rules together into one big SELECT statement, you have a mess to troubleshoot when one of the rules changes or when you discover that you have a bug.

Of course, when you are all done and it goes into a system with actual records, some processes perform so slowly that you have to go back and rewrite with performance as your primary goal.