Friday, November 5, 2010

On perspective (or "concentrate on what's important")

"We already have this great framework we use during the main data processing, why not for user management?"
Or
"There's already a bulk of code responsible for loading and saving millions of records - why should I write something new to load and save configuration records (all 10 of them)?"

I hear those (and similar) often. Or worse, I don't hear them, just see the commits in the version control. I think this is a price we pay for modularizing our code. The more functional and setup-free, the easier it is to reuse a piece of code in many contexts.

When a developer write a piece of code, he usually has a specific use-case in mind. This drives performance requirements, defaults, existing fixtures that need to be in place and other "non-functional" requirements. Innocently, that developer checks-in the code, usually along with it's dependent "client" code (and hopefully, some tests), and says to himself "Good job. Well done, me - time for some coffee".
Then, another developer appears. Let's call the first one "Fred", for being a Framework developer, and the newcomer "Cliff", for developing a new Client code.
So, anyway, Cliff comes in with a new requirement - create a client to change a specific configuration. Since Cliff is "constructively lazy", he asks around for some similar pieces of code to what he needs. Cliff finds Fred, still drinking his coffee and basking in the warmth that comes from a job well done. Fred tells Cliff - "Oh yes, I've just checked-in a very useful piece of code for the highly complex, extremely sensitive, super-important project from the high-lord boss. It's a beauty.". Cliff is happy now - all he needs to do for his tiny client part that, truly, is not that important to the main business, is link it with the shiny new framework Fred has written. He does so, and shortly joins Fred for some black tea (anything with caffeine goes...).
The result is that now both the "super important" code (main data processing, critical engine part, analysis engine...) and the relatively "less important" code (system configuration load and save) use the same underlying code - the framework code. However, all Cliff needed was a simple SQL statement - one for loading, one for writing.

Think about it like this - it's reasonable to hire a chef to cater for out important formal Dinner. However, you probably don't want the same chef, his sous-chefs, the kitchen boy and the delivery girl all running in your kitchen, just because you're peckish and want to grab a cold snack.
The smarter that framework is, the more sophisticated its analyzers are, the bigger the cost is when using it on a non-main path. Easy tasks should have easy solutions. The fact that the engine is there, ready to be used, doesn't mean it should be used - there are usually many hidden costs ("non functional" - remember?). Not to mention the extra coincidental dependency that now exists. Think about it the other way around - you wouldn't use the simple code for your main flow. If you try that, you'll hit problems very soon - performance, compatibility, corner cases. However, no one thinks twice about using the complex code in use cases analogous to opening the fridge and getting a chocolate bar.

To finish, a very known quote from an old Chinese master (paraphrased): "Don't use a cannon to kill a mosquito".

No comments:

Post a Comment