Wednesday, May 09, 2012

There's Never Time To Do It Right....

I got bit today by a bit of false economy.

We had a message to a piece of hardware that needed a flag sent, but there was no time to alter the existing protocol to add an explicit flag.  So someone, years ago, resorted to a little bit-twiddling in an existing field.  However, instead of setting that bit in the field right at the places where it was correct to set, they put the check and set in a function called later.

Fast-forward to now, when I move some code to fix another issue, and this bit setting is now hidden away from the field population, so I have a value that is mangled after I use it, and the bit is not set correctly.

The only reason I can think of for why the original developer did not just put the check and set in the places it was needed is that doing so would alter more files, and someone decided it was better to make a change in one file.  In other words, a false economy, one that would have been better to have changes the multiple files and put the change near its use instead of in another function almost wholly unrelated.

So think well before you allow someone to tell you that its better to compromise proper separation of concerns.