Metrics from previous TwinCAT versions
Metrics from versions < TwinCAT 3.1.4026.14:
Column abbreviation in Standard Metrics view | Description |
|---|---|
Prather | Complexity of nesting (Prather) |
n1 (Halstead) | Halstead – number of different used operators (n1) |
N1 (Halstead) | Halstead – number of operators (N1) |
n2 (Halstead) | Halstead – number of different used operands (n2) |
N2 (Halstead) | Halstead – number of operands (N2) |
HL (Halstead) | Halstead – length (HL) |
HV (Halstead) | Halstead – volume (HV) |
D (Halstead) | Halstead – difficulty (D) |
Complexity of nesting (Prather)
Nesting weight = statements * nesting depth
Complexity of nesting = nesting weight / number of statements
Nesting through IF/ELSEIF or CASE/ELSE statements, for example.
Halstead (n1, N1, n2, N2, HL, HV, D)
The following metrics are part of the "Halstead" range:
- Number of different used operators - Halstead (n1)
- Number of operators - Halstead (N1)
- Number of different used operands - Halstead (n2)
- Number of operands - Halstead (N2)
- Length - Halstead (HL)
- Volume - Halstead (HV)
- Difficulty - Halstead (D)
Background information:
- Relationship between operators and operands (number, complexity, test effort)
- Based on the assumption that executable programs consist of operators and operands.
- Operands in TwinCAT: variables, constants, components, literals and IEC addresses.
- Operators in TwinCAT: keywords, logical and comparison operators, assignments, IF, FOR, BY, ^, ELSE, CASE, Caselabel, BREAK, RETURN, SIN, +, labels, calls, pragmas, conversions, SUPER, THIS, index access, component access, etc.
For each program the following basic parameters are formed:
- Number of different operators used - Halstead (n1),
Number of different operands used - Halstead (n2): - Number of different used operators (h1) and operands (h2); together they form the vocabulary size h.
- Number of operators - Halstead (N1),
Number of operands - Halstead (N2): - Number of total used operators (N1) and operands (N2); together they form the implementation class N.
- (Language complexity = operators/operator occurrences * operands/operand occurrences)
These parameters are used to calculate the Halstead length (HL) and Halstead volume (HV):
- Length - Halstead (HL),
Volume - Halstead (HV): - HL = h1* log2h1 + h2* log2h2
- HV = N* log2h
Various key figures are calculated from the basic parameters:
- Difficulty - Halstead (D):
- Describes the difficulty to write or understand a program (during a code review, for example)
- D = h1/2 *N2/h2
- Effort:
- E = D*V
The key figures usually match the actual measured values very well. The disadvantage is that the method only applies to individual functions and only measures lexical/textual complexity.