17 August 2011

If (false) may be useful

Can you be friend with this kind of dead code? In this particular subject my opinion is slightly different from the general. I can agree that in the ideal programming world there is no need to use dead code, but in reality there are situations when it's good to consider this solution as appropriate.

Standard solution (JavaDoc)

As I previously wrote here, JavaDoc is not perfect as well. Of course, if we have a lot of time, our code will look really good. Unfortunately, most of us do not have such amount of time, so we cannot become JavaDoc-Shakespeare if we want to be truly agile.

Another solution (JavaDoc-Code)

At first I used to replace some descriptions in JavaDoc with pure code. It can become handy in many ways. Code is precise so (mostly) there is no need to wander about its meaning - invaluable in multi-language team and not only there. Problem is in its volatility - each refactor including simple variable renaming can bring serious harm to our JavaDoc-Code, also code witch is no code (there is no compiler validation) can contains expressions that are understandable only for the author. Those reasons make this method (more or less) meaninglessness.

Useful !/?

Don't get me wrong this is not the solution that should be used often, however my experience shows that it can be useful. One of such a moment is when we have to reimplement some important method long to a few hundred lines. To make backup always available SVN will be not enough (at least till next generation), as some serious refactor can make it almost useless. Also developers are more minded for applying changes to both dead path and active one, if they find dead code with good explanation, what, of course, is impossible for code in the repository! So basically, if you do not like to tell/force people not to make refactor because you have some important code in repository - consider using dead code.

How! / When?

If you are in such a comfortable situation and your project have test, testers and there is a lot of time between bug and fix, dead code is probably not for you.
But if your project lack some of those things and still after all, you do not want to take it as excuse for your bugs then consider dead code as you temporary friend.

0 comments / komentarz(y):

Post a Comment