Database Reference
In-Depth Information
Figure 5-5. An example of a CoverStory session
Generating Code Complexity Metrics
Over the last few years, code complexity metrics have become the hot new measure of
code goodness. Simply put, cyclomatic complexity numbers (CCN) are a measure of
how many ways there are of getting through a given piece of code. The more conditional
code you have in a method, the deeper you nest your if statements, the more looping
you're doing, the higher your numbers are going to be.
Different organizations have different acceptable levels of complexity. For example, a
company might mandate that any new code must have a CCN lower than 20, while
old code must be refactored if the number is higher than 50. Getting numbers down
typically involves breaking up large methods into smaller ones, and is generally a good
thing, although I've seen cases where code actually ended up less readable as a result
of trying to knock down high CCN numbers.
In the Java world, tools like Coverity are routinely used to generate CCN metrics, and
even to fail builds based on them. In my searches, I've only found one good tool to
compute CCN metrics for Objective-C, and it's just a Python script that a guy named
Terry Yinzhe threw together under the Apache license. It's called hfcca13.py , and it's
included in the example code for the topic (see “How to Contact Us” on page ix ).
 
Search WWH ::




Custom Search