« Java Mock Object Framework Comparison | Main | The State Transition Game »

February 25, 2005

The difference between knowing and understanding

I suspect that the vast majority of us carry around a huge arsenal of "best practice" idioms - the veracity of which, like Martin Luther King, "we hold to be self-evident". Indeed, the whole Patterns movement has come about to spread this collectively-gained knowledge and prevent the endless rediscovery and reinvention of the wheel. Having such information readily on hand removes the need to suffer the pain arising from violating these idioms. Something along the lines of "if we have seen further, it's because we've stood on the rotting corpses of previous development teams".

Yet yesterday I received one of those harsh slap-in-the-face lessons that occurs when you're forced to deal with a violation of these central tenets of good software design. The context was a refactoring session and the problem was caused by code ignoring the classic "separation of command and query" principle. Specifically, my pair and I stumbled across a method which at first glance looked like an innocent accessor (i.e., getFoo()). We were refactoring the class containing this code and one of it's clients...

Suddenly, the test we were running began behaving in a very strange fashion: seemingly, the code in which our breakpoints were positioned was no longer being executed! This confounded our two little brains for some time before it became clear what had happened: the practical upshot of refactoring out the call to our now no-so-innocent getFoo() was that the side effect it contained (which had previously resulted in our breakpoints being triggered) was no longer occurring. What we thought was a simple query method contained an undocument command that changed the state of the class itself! D'oh!

Now I'd known of the separation principal for many a long year, but it had become such a sub-conscious thing that I never really appreciated the damage that violating this principal can cause until I stood toe-to-toe with this delight yesterday. The end result is that I'll be super-duper careful of this issue from now on and hunt down offenders with a fanatical vigour. But I almost regret not having similar exposure to other such violations in order to harden my resolve in those directions as well. After all, there is a world of difference between being told a kettle sitting on the stove is very hot and receiving a nasty burn from the same.

Posted by Andy Marks at February 25, 2005 10:57 AM

Comments

Post a comment

Thanks for signing in, . Now you can comment. (sign out)

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)


Remember me?