## Metrics

### Kiviat Chart

A kiviat chart visually displays a set of metrics that provides easy viewing of multiple metrics against minimum and maximum thresholds.  Each radial of Kiviat chart is a metric.  All metrics are scaled so that all maximums are on a common circle and all minimums are on a common circle.

In the charts below the red circle is the maximum threshold and the blue band is the minimum threshold.  The white band between the two is the acceptable range.  The chart on the left shows that all metrics are well within the acceptable range.  The chart on the right shows an example where all metrics are above maximum limits.

 Good.   All metrics within limits. Bad.   All but one (cLOC) of the metrics above high limit.

DevCodeMetricsWeb screen shot with Kiviat:

### Cyclomatic Complexity (Vg)

Cyclomatic complexity (Vg) is a calculation of function/method complexity.  It gives one indication of function readability.

 Vg Evaluation 1-10 Simple, low complexity 11-20 Moderate risk 21-50 High risk > 50 Not testable

Cyclomatic complexity is a count of the number of basic decision in a function by assigning 1 point to each of the following:

• The function
• Each if, while, switch, case, and for statement
• Each || or && within a conditional.

For example the following function has a Vg of 4.

void foo(int iLimit)

{

int iFooVar1;

for (iFooVar1 = 0; (iFooVar1 < iLimit) && (iFoovar1 < 1000); iFooVar++)

{

if (iSomeGlobal > 42)

{

doSomeThingClever();

}

}

}

### Lines Of Code (LOC)

Lines of code (LOC) is a count of each line that has any code element.  It is easy to measure but almost impossible to interpret as is highly dependent on coding standard, language, environment, and coders skill (good coders may do the same with fewer lines).

For example, the table below shows the same code written with different coding standards.  The difference is 70%.

 if (iValue > 42) { if (iAnotherValue != 0) { doSomethingClever(); } } if (iValue > 42 && iAnotherValue != 0) doSomethingClever(); LOC = 7 LOC = 2

A better measure of effort may be effective lines of code (eLOC).  For a more detailed discussion of LOC go to http://c2.com/cgi/wiki?LinesOfCode.

Effective lines of code (eLOC)

Cyclomatric Complexity (Vg)

Kiviat Charts

### Effective Lines Of Code (eLOC)

Effective lines of code (eLOC) is a count of code statements.  It provides a better measurement of effort than lines of code (LOC) and is a complexity indicator.

For example the following code has a 4 effective lines of code.

if (iValue > 42)

{

doSomethingClever();

doSomethingElse();

a = b + c;

}