While working on existing code base, I usually come across procedures that contain Abusive use of IF and Switch statements. The procedures consist of overwhelming code, which I think require re-factoring badly. The situation gets worse when I identify that some of these are recursive as well.
But this is always a matter of debate as the code is working fine and no one wants to wake up the dragon. But, everyone accepts it is very expensive code to manage. I am wondering if are any recommendations to determine if a particular Method is a culprit and needs a revisit/rewrite , so that it can broken down or polymophized in an effective manner. Are there any Metrics (like no. of lines in procedure) that can be used to identify such segment of code. The checklist or advice to convince everyone, will be great!
if/elseif/else
block that is 20,000 lines; that is a huge statement machine that isn't going to be able to be easily reasoned about ( same with a switch ). There are some great alternatives such as theChain of Responsibility
pattern or theStrategy Pattern
to deal with unwieldy code like this. – Jun 29 '12 at 12:50