|
Re: Pardon My French, But This Code Is C.R.A.P. (2)
|
Posted: Sep 4, 2007 7:55 AM
|
|
Hi Andrew,
Thank you for the suggestion. I can see you know your Cyclomatic Complexity well :-).
We looked at a lot of code, and case statements did stick out as something that might deserve a special treatment. The reason we did not rush to give case statements such treatment in version 0.1 of the metric is that there are examples - lots of them - where it could be replaced by something simpler, safer, and more elegant.
The canonical example of this is uses of the case statements to map, say, state abbreviations (e.g. CA) into state names (e.g. California) or state tax calculations (e.g. 8.25 in CA). We've seen several examples of people doing this with 50+ case statements. Is this the best way?
Some people argued that a HashMap would be a better way to implement this and that, generally speaking, if you need tens of case statements to accomplish something, that might be an indication that there might be a better design lurking somewhere.
What do you folks think. Anyone willing to make a case for the case statement NOT receiving preferential treatment?
Actual examples would be most compelling.
Alberto
|
|