Agile Quality Tip #5 - Manage Code Complexity
Posted on Thu, Mar 03, 2011
As we wrote previously, our current series of posts is covering 10 brief quality tips designed to help you extend well-known agile quality practices to ensure that your software satisfies business needs—effectively and efficiently.
Tip #5 is "Manage Code Complexity."
Metrics, as most people think of them, aren't incredibly helpful. Assume that I have a million lines of code. If I find out that the code has an average Cyclomatic Complexity of 9 or 6, what does this tell me? Not much.
However, since overly-complex code has time and time again been proven to be slower, more difficult, and more risky to update and extend than simpler code, it is helpful to zero in on complex code—say, any class or method whose Cyclomatic Complexity is 10 or higher. This code might work fine right now, but it could cause the team considerable grief down the road when what appeared to be a simple functionality extension ends up requiring a large-scale rewrite.
Using the metrics calculations for one of your easy-to-maintain projects as a guideline, set realistic boundaries and thresholds for selected metrics, then ensure that team members are alerted when metrics are outside of the prescribed range.
This will reduce the time and effort required to modify and extend code in subsequent iterations. It will also help new developers get up to speed faster.

For a more detailed discussion about code metrics and other static analysis techniques, read our Static Analysis Starter Kit.
Learn more about how Parasoft's static analysis helps you assess and manage code complexity.