views:

309

answers:

4

Hi all. I'm interested in data mining projects, and have always wanted to create a classification algorithm that would determine which specific check-ins need code-reviews, and which may not.

I've developed many heuristics for my algorithm, although I've yet to figure out the killer...

How can I programmatically check the computational complexity of a chunk of code?

Furthermore, and even more interesting - how could I use not just the code but the diff that the source control repository provides to obtain better data there..

IE: If I add complexity to the code I'm checking in - but it reduces complexity in the code that is left - shouldn't that be considered 'good' code?

Interested in your thoughts on this.

UPDATE

Apparently I wasn't clear. I want this

double codeValue = CodeChecker.CheckCode(someCodeFile);

I want a number to come out based on how good the code was. I'll start with numbers like VS2008 gives when you calculate complexity, but would like to move to further heuristics.

Anyone have any ideas? It would be much appreciated!

+3  A: 

Have you taken a look at NDepend? This tool can be used to calculated code complexity and supports a query language by which you can get an incredible amount of data on your application.

JaredPar
darn ! beat me by seconds!!
Mitch Wheat
A: 

The NDepend web site contains a list of definitions of various metrics. Deciding which are most important in your environment is largely up to you.

NDepend also has a command line version that can be integrated into your build process.

Mitch Wheat
A: 

Also, Microsoft's Code Analysis (ships with VS Team Suite) includes metrics which check the cyclomatic complexity of code, and raises a build error (or warning) if this number is over a certain threshold.

I don't know off hand, but ut may be worth checking whether this number is configurable to your requirements. You could then modify your build process to run code analysis any time something is checked in.

Winston Smith
A: 

See Semantic Designs C# Metrics Tool for a tool that computes a variety of standard metrics value both over complete files, and all reasonable subdivisions (methods, classes, ...).

The output is an XML document, but extracting the value(s) you want from that should be trivial with an XML reader.

Ira Baxter