Language Scope
Cost of maintaining or changing a function
Description
This metric measures the cost of maintaining or changing a function. It is calculated as:
(N1 + N2)/(n1 + n2)
N1
is the number of occurrences of operators.Other than identifiers (variable or function names) and literal constants, everything else counts as operators.
N2
is the number of occurrences of operands.n1
is the number of distinct operators.n2
is the number of distinct operands.The metric considers a literal constant with a suffix as different from the constant without the suffix. For instance, 0 and
0U
are considered different.
When reporting this metric, Polyspace® rounds the calculated language scope to the first decimal place. Because the intent of this metric is to indicate the maintainability of a function, language scope of functions defined within local classes are not computed.
Tip
To find N1 + N2
, count the total number of tokens. To find
n1 + n2
, count the number of unique tokens.
The recommended upper limit for this metric is 4. For lower maintenance cost for a function, try to enforce an upper limit on this metric. For instance, if the same operand occurs many times, to change the operand name, you have to make many substitutions.
To enforce limits on metrics, see Compute Code Complexity Metrics Using Polyspace.
Examples
Metric Information
Group: Function |
Acronym: VOCF |
HIS Metric: Yes |