SourceMonitor

SourceMonitor is a free source code analysis tool from Campwood Software. It will analyze source code in a variety of languages including C# and C++, Delphi (Object Pascal) and Java. It allows you to store a series of checkpoints detailing various complexity metrics over time and can help to locate targets for refactoring and simplification.

Here is a screenshot of some metrics for PN before the recent refactoring of the code that transforms XML schemes into instructions for the Scintilla editing component:

Scheme Compiler Metrics

The source files here are sorted according to Max Complexity. The Scheme Compiler here is pretty complex compared to a lot of the other code. Interestingly, the refactoring did not reduce this complexity by much as can be seen here:

Scheme Compiler Complexity After

The number of lines of code and statement counts have shot down due to re-organisation and refactoring but the complexity has only reduced by a small amount. Clearly parts of this code are still quite likely to be difficult to follow and understand for anyone not used to it.

Of course, no metrics tool is worth anything without graphs, double clicking on the SchemeCompiler.cpp file brings up a nice little dialog with in-depth details about that code file: Scheme Compiler Analysis

The tool can also graph various of the metrics in a graph window on their own. I particularly like the Kiviat Graph which shows that complexity is high and comment content is low suggesting some under-commented complex code! Not all of the metrics this program can show you are necessarily useful and it’s easy to jump to the wrong conclusions about what work would be useful based purely on analysis like this but overall I like it! A useful free tool for analysing your code: SourceMonitor