Determining Code Complexity

Having inherited a lot of code in past lives as a development lead or dev manager, determining code complexity was something that always fascinated me. I use to have conversations about this with some of my senior developers about this. Luckily, we had the luxuary of building the code ourselves rather receiving the code from outsources. We were pretty brutal on each other's code (they were extremely brutal of mine since I was their manager) so we tried to write the best code we could and make it maintainable at the same time.

Using contractors, local shore, near shore, and/or off-shore resources is so common, doing a complexity check on the code you receive should be one the gauges you use to determine the usefulness of the code you receive. What good is thousands of lines of code if you or your team can't maintain it? You really don't want to be beholden to the outsource to maintain the code. Obviously they need to be responsible for the code working in the first place, but once the contact ends or the phase of the project is complete, you'll want to make sure your team can maintain the code effectively.

The above mentioned situation(s) should not be a new concept. One of my developers pointed me to paper written back in 1976 written by Tom McCabe called A Complexity Measure. The basic idea behind his theory is that code complexity is defined by its control flow. If you look up McCabe on the Wiki, you will find an article on Cyclomatic complexity which helps introduce lot of good background on the original article. Mark Swanson, a Microsoft Technical Evangelist, wrote a good article on Code Review and Complexity and how the McCabe theory is used.  

In the Visual Studio Team System 2008 Developer Edition, we added features to help check code complexity and provide a maintainability index, in which we based it on concepts and algorithms by McCabe. For more information on how we its implemented, see the following blogs by the Visual Studio Code Analysis Team:

Code Metrics

Maintainability Index Range and Meaning

For people who are still maintaining code older than .NET 2.0, there is a free daily code metric utility called SourceMonitor by Campwood Software.



Comments (1)

  1. Dajung on Determining Code Complexity. Michael Ruminer on TFS Admin Tool on Codeplex. Tim Hibbard on…

Skip to main content