views:

387

answers:

11

I'm interested in finding some software that can analyze some C# files or an entire C# project/solution and give it a score which rates its ease or difficulty to maintain. Are there products or methods out there that do this?

A: 

You should check out cyclomatic complexity. I dont know if there is a tool for .net, but if you do a search on it, i bet you'll find results.

Kevin
"Cyclomatic" complexity.
sixlettervariables
+7  A: 

Cyclomatic complexity is a good indication of maintainability. It is a measurement of the number of different paths through your source code.

For C#, take a look at these examples and links for tools.

Magnar
A: 

cyclomatic complexity i.e. the number of logic branches can give you a measure of how difficult a module is to test and maintain.

Bedwyr Humphreys
+2  A: 

If you use Visual Studio 2008 many metrics are built right into the IDE. If you use Visual Studio 2005, or would like a stand alone system. devAdvantage/devMetrics is your answer. All of these tools produce multiple measures, including Cyclomatic Complexity that @Kevin discussed.

sixlettervariables
+2  A: 

while reading the code to determine the complexity you can have someone count your WTFs per minute ;-)

Brian G
A: 

There is no automated bulletproff way to do this. You can run a number of lint-like tools, but they're generally able to point out syntactic issues, not semantic ones. It is valuable anyway, i.e. they may tell you about unreadable code, risky constructs, etc. but won't tell you that the design is not extensible, that the code is not tested etc.

phjr
A: 

I believe you need VS 2008 dev or team system. However if you do have it, then the Code Metrics feature provides a number of different metrics including cyclomatic complexity. It will also roll tose metrics up into a 'maintainability index'.

Steve Steiner
+6  A: 

There is a Tool called SourceMonitor. It scans and analyzes your source code and rates it. You can find it here http://www.campwoodsw.com/

frast
Note: SourceMonitor is free, and works with C++, C, C#, VB.NET, Java, Delphi, Visual Basic (VB6) or HTML. I integrated SourceMonitor metrics into our CI server primarily due to it's large language base.
VanSkalen
+6  A: 

There is actually a software metric called maintainability index. developed by SEI-CMU.

It is based on Halstead Metrics, Cyclomatic complexity, LOC and Percent comments.

In short the formula is 171 - 5.2 * ln(aveV) - 0.23 * aveV(g') - 16.2 * ln (aveLOC) + 50 * sin (sqrt(2.4 * perCM))

More details : http://www.sei.cmu.edu/str/descriptions/mitmpm.html

Midhat
+1  A: 

Code Coplexity is taking into account as well as some other things (coupling, cohesion, inheritance levels) to formulate a Maintainability Score in the Team System tools. If you are running a Team System SKU of Visual Studio, that is the bombshell you are after.

David Starr - Elegant Code
A: 

Jumping in after a long time dead, NDepend does what you need and more.

Scott Hanselman has a lot of information on using it and a good overview in his easily digested podcast.

graham.reeds