When anaylizing some cyclomatic complexity (measures the number of linearly-independent paths through a program module), I was thinking to myself about where I want my thresholds to be. Where to I say “this is simple enough” or “I definately need to refactor this”.
So here is my conclusion:
- 1–10 Simple enough. Don’t change. Little risk involved.
- 11–20 Should consider refactoring. Moderate risk involved.
- 21–40 Definate refactoring needed here. Risk is too high.
- > 41 What was I thinking? Throw this away and start over.
I won’t find anything in the greater than 41 range, but if I were to find anything, I’d definately throw it away.
Raymond, I was just blogging about this topic: http://devreflection.wordpress.com/2007/06/11/cyclomatic-complexity-and-refactoring/
Do you have any suggestions for the scenario I describe in the post (specifically I’ve got a class that’s a concrete implementation of System.Xml.XPath.XmlNavigator–lots of abstract methods are defined on that class ;( )?
Have a look at FxCop or the Managed Code Analysis in Team System.
Doesn’t analyze source code but rather the binary and also does CCC (Team System version only).
I posted this before I saw Sahil’s comment, but here is a link to some tools I use: http://www.codebetter.com/blogs/raymond.lewallen/archive/2005/06/13/64539.aspx
Answer to Eric’s question – http://codebetter.com/blogs/sahil.malik/archive/2005/06/13/64537.aspx
Are there any solid tool for doing source code analysis of .NET programs?