compute Halstead's software science metrics
Maple procedure, module, or list of procedures or modules
(optional) BooleanOpt(summarize); specifies whether to return the output in a tabular format or as an expression sequence containing a row Vector and a listlist structure
The HalsteadMetrics routine computes Maurice Halstead's software science metrics for each procedure or module contained in the parameter prc. Altogether, there are six metrics, all of which are functions of the following four variables:
n1 = the number of unique operators
n2 = the number of unique operands
N1 = the total number of operators
N2 = the total number of operands
The six software science metrics include:
Vocabulary: n=n1+n2 (the total number of unique operators and operands)
Length: N=N1+N2 (the sum of all occurrences of operators and operands)
Volume: V=N⁢log2⁡n (quantifies the total size of a given procedure)
Program Difficulty: D=n1⁢N22⁢n2 (reflects the effort required to understand, code, and maintain a given procedure)
Language Level: L=VD2 (indicates how well a programmer uses features of the language)
Effort: E=D⁢V (indicates a level of program complexity in units of time that it takes to write, modify, or maintain a piece of code)
The summarize option (sm) controls how the result is returned.
If the summarize option is omitted (or is given as summarize=false), the result returned is an Array which tabulates the six Halstead metrics along with the operator/operand counts for each procedure and module contained in the parameter prc.
To force the display of large Arrays, you can increase the rtablesize setting using the interface function.
If given as summarize=true, the result returned is an expression sequence containing a row Vector and a listlist structure. The row Vector stores the six Halstead metrics and the listlist structure stores the operator/operand counts. For this case, the metrics are computed just once and take into account all procedures and modules contained in prc.
The condition summarize=true can be abbreviated as summarize.
Example procedure taken from the Maple Programming Guide
sieve := proc(n::integer)
local i, k, flags, count, twice_i;
count := 0;
for i from 2 to n do flags[i] := true end do;
for i from 2 to n do
if flags[i] then
twice_i := 2*i;
for k from twice_i by i to n do flags[k] := false end do;
count := count+1;
Halstead's MetricsOperator/Operand Count[n,N,V,D,L,E][[n1,N1],[n2,N2]]sieveTypesetting:-_Hold⁡131970.308354621.80000000021.70010945126.55503833,7,10,12
Examples using Maple library code
Halstead's MetricsOperator/Operand Count[n,N,V,D,L,E][[n1,N1],[n2,N2]]dsolveTypesetting:-_Hold⁡1574123005.38374850.587962961.1743716261.520362417⁢10549,189,108,223dsolve/numericTypesetting:-_Hold⁡579286526293.30698151.17718941.1504630593.974948249⁢10688,1178,491,1687
Halstead's MetricsOperator/Operand Count[n,N,V,D,L,E][[n1,N1],[n2,N2]]CurveFitting:−ArrayInterpolationTypesetting:-_Hold⁡287147512043.2377289.271966531.5111690681.075123515⁢10648,586,239,889CurveFitting:−BSplineTypesetting:-_Hold⁡3682423.933850015.272727271.8174601716474.62607214,34,22,48CurveFitting:−BSplineCurveTypesetting:-_Hold⁡53129738.901738717.944444442.29470390213259.1812017,53,36,76CurveFitting:−InteractiveTypesetting:-_Hold⁡00undefinedundefinedFloat⁡undefinedFloat⁡undefined0,0,0,0CurveFitting:−LeastSquaresTypesetting:-_Hold⁡801861175.87862626.962962961.61743659931705.1718426,74,54,112CurveFitting:−LowessTypesetting:-_Hold⁡222.0.50000000008.0000000001.0000000001,1,1,1CurveFitting:−PolynomialInterpolationTypesetting:-_Hold⁡771651034.01977921.283018872.28277120622007.0624724,71,53,94CurveFitting:−RationalInterpolationTypesetting:-_Hold⁡892331508.84588937.413793101.07790727656451.6479131,93,58,140⋮⋮⋮12 × 3 Array
Download Help Document
What kind of issue would you like to report? (Optional)