Wednesday, October 20, 2010

Removing "Configuration Flag" Code ...

I had the pleasure of working on some code with @edleafe recently. It was a change in some existing functionality. This change could be turned from "old way" to "new way" with a configuration flag, which is pretty normal practice and encouraged.

The issue with "Configuration Code" is that after a while you have two blocks of code that you have to maintain. One for the old way, one for the new way. And, hopefully, there are tests around the old code and the new code.

What has always bothered me that once the flag gets set and its state stabilizes, the old code should be ripped out and the flag removed. The reality is, this never seems to happen. When was the last time you grep'ed for TODO? So you end up with these Conditional Code blocks all over the place. It's worse when your flag touches many parts of the code.

Ed had a great idea. Add a ticket to your bug tracker to remove the conditional code and the flag. Product management can review the bug from time to time and determine when the flag is no longer needed. It becomes a thorn in everyone's side until it gets removed.

Simple solution and maybe it's common practice, but I had never considered or heard of it before. I like it.

0 comments: