SoftwareMetrics

Parameters

 prc - Maple procedure, module, or list of procedures or modules sm - (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

Description

 • 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=\mathrm{n1}+\mathrm{n2}$   (the total number of unique operators and operands)
 Length: $N=\mathrm{N1}+\mathrm{N2}$   (the sum of all occurrences of operators and operands)
 Volume: $V=N{\mathrm{log}}_{2}\left(n\right)$   (quantifies the total size of a given procedure)
 Program Difficulty: $\mathrm{D}=\frac{\mathrm{n1}\mathrm{N2}}{2\mathrm{n2}}$   (reflects the effort required to understand, code, and maintain a given procedure)
 Language Level: $L=\frac{V}{{\mathrm{D}}^{2}}$   (indicates how well a programmer uses features of the language)
 Effort: $E=\mathrm{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.

Examples

 > $\mathrm{with}\left(\mathrm{SoftwareMetrics}\right):$

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;         end if;     end do;     count; end proc:
 > $\mathrm{HalsteadMetrics}\left('\mathrm{sieve}'\right)$
 $\left[\begin{array}{ccc}{}& {\mathrm{Halstead\text{'}s Metrics}}& {\mathrm{Operator/Operand Count}}\\ {}& {\mathrm{\left[n,N,V,D,L,E\right]}}& {\mathrm{\left[\left[n1,N1\right],\left[n2,N2\right]\right]}}\\ {\mathrm{sieve}}& {\mathrm{Typesetting}}{:-}{\mathrm{_Hold}}{}\left(\left[\left[\begin{array}{cccccc}13& 19& 70.30835462& 1.800000000& 21.70010945& 126.5550383\end{array}\right]\right]\right)& \left[\left[{3}{,}{7}\right]{,}\left[{10}{,}{12}\right]\right]\end{array}\right]$ (1)
 > $\mathrm{HalsteadMetrics}\left('\mathrm{sieve}','\mathrm{summarize}'\right)$
 $\left[\begin{array}{cccccc}{13}& {19}& {70.30835462}& {1.800000000}& {21.70010945}& {126.5550383}\end{array}\right]{,}\left[\left[{3}{,}{7}\right]{,}\left[{10}{,}{12}\right]\right]$ (2)

Examples using Maple library code

 > $\mathrm{HalsteadMetrics}\left(\left['\mathrm{dsolve}','\mathrm{dsolve/numeric}'\right]\right)$
 $\left[\begin{array}{ccc}{}& {\mathrm{Halstead\text{'}s Metrics}}& {\mathrm{Operator/Operand Count}}\\ {}& {\mathrm{\left[n,N,V,D,L,E\right]}}& {\mathrm{\left[\left[n1,N1\right],\left[n2,N2\right]\right]}}\\ {\mathrm{dsolve}}& {\mathrm{Typesetting}}{:-}{\mathrm{_Hold}}{}\left(\left[\left[\begin{array}{cccccc}157& 412& 3005.383748& 50.58796296& 1.174371626& 1.520362417{}{10}^{5}\end{array}\right]\right]\right)& \left[\left[{49}{,}{189}\right]{,}\left[{108}{,}{223}\right]\right]\\ {\mathrm{dsolve/numeric}}& {\mathrm{Typesetting}}{:-}{\mathrm{_Hold}}{}\left(\left[\left[\begin{array}{cccccc}579& 2865& 26293.30698& 151.1771894& 1.150463059& 3.974948249{}{10}^{6}\end{array}\right]\right]\right)& \left[\left[{88}{,}{1178}\right]{,}\left[{491}{,}{1687}\right]\right]\end{array}\right]$ (3)
 > $\mathrm{HalsteadMetrics}\left('\mathrm{CurveFitting}'\right)$
 $\begin{array}{c}\left[\begin{array}{ccc}{}& {\mathrm{Halstead\text{'}s Metrics}}& {\mathrm{Operator/Operand Count}}\\ {}& {\mathrm{\left[n,N,V,D,L,E\right]}}& {\mathrm{\left[\left[n1,N1\right],\left[n2,N2\right]\right]}}\\ {\mathrm{CurveFitting}}{:-}{\mathrm{ArrayInterpolation}}& {\mathrm{Typesetting}}{:-}{\mathrm{_Hold}}{}\left(\left[\left[\begin{array}{cccccc}287& 1475& 12043.23772& 89.27196653& 1.511169068& 1.075123515{}{10}^{6}\end{array}\right]\right]\right)& \left[\left[{48}{,}{586}\right]{,}\left[{239}{,}{889}\right]\right]\\ {\mathrm{CurveFitting}}{:-}{\mathrm{BSpline}}& {\mathrm{Typesetting}}{:-}{\mathrm{_Hold}}{}\left(\left[\left[\begin{array}{cccccc}36& 82& 423.9338500& 15.27272727& 1.817460171& 6474.626072\end{array}\right]\right]\right)& \left[\left[{14}{,}{34}\right]{,}\left[{22}{,}{48}\right]\right]\\ {\mathrm{CurveFitting}}{:-}{\mathrm{BSplineCurve}}& {\mathrm{Typesetting}}{:-}{\mathrm{_Hold}}{}\left(\left[\left[\begin{array}{cccccc}53& 129& 738.9017387& 17.94444444& 2.294703902& 13259.18120\end{array}\right]\right]\right)& \left[\left[{17}{,}{53}\right]{,}\left[{36}{,}{76}\right]\right]\\ {\mathrm{CurveFitting}}{:-}{\mathrm{Interactive}}& {\mathrm{Typesetting}}{:-}{\mathrm{_Hold}}{}\left(\left[\left[\begin{array}{cccccc}0& 0& \mathrm{undefined}& \mathrm{undefined}& \mathrm{Float}{}\left(\mathrm{undefined}\right)& \mathrm{Float}{}\left(\mathrm{undefined}\right)\end{array}\right]\right]\right)& \left[\left[{0}{,}{0}\right]{,}\left[{0}{,}{0}\right]\right]\\ {\mathrm{CurveFitting}}{:-}{\mathrm{LeastSquares}}& {\mathrm{Typesetting}}{:-}{\mathrm{_Hold}}{}\left(\left[\left[\begin{array}{cccccc}80& 186& 1175.878626& 26.96296296& 1.617436599& 31705.17184\end{array}\right]\right]\right)& \left[\left[{26}{,}{74}\right]{,}\left[{54}{,}{112}\right]\right]\\ {\mathrm{CurveFitting}}{:-}{\mathrm{Lowess}}& {\mathrm{Typesetting}}{:-}{\mathrm{_Hold}}{}\left(\left[\left[\begin{array}{cccccc}2& 2& 2.& 0.5000000000& 8.000000000& 1.000000000\end{array}\right]\right]\right)& \left[\left[{1}{,}{1}\right]{,}\left[{1}{,}{1}\right]\right]\\ {\mathrm{CurveFitting}}{:-}{\mathrm{PolynomialInterpolation}}& {\mathrm{Typesetting}}{:-}{\mathrm{_Hold}}{}\left(\left[\left[\begin{array}{cccccc}77& 165& 1034.019779& 21.28301887& 2.282771206& 22007.06247\end{array}\right]\right]\right)& \left[\left[{24}{,}{71}\right]{,}\left[{53}{,}{94}\right]\right]\\ {\mathrm{CurveFitting}}{:-}{\mathrm{RationalInterpolation}}& {\mathrm{Typesetting}}{:-}{\mathrm{_Hold}}{}\left(\left[\left[\begin{array}{cccccc}89& 233& 1508.845889& 37.41379310& 1.077907276& 56451.64791\end{array}\right]\right]\right)& \left[\left[{31}{,}{93}\right]{,}\left[{58}{,}{140}\right]\right]\\ {⋮}& {⋮}& {⋮}\end{array}\right]\\ \hfill {\text{12 × 3 Array}}\end{array}$ (4)
 > $\mathrm{HalsteadMetrics}\left('\mathrm{CurveFitting}','\mathrm{summarize}'\right)$
 $\left[\begin{array}{cccccc}{492}& {2941}& {26299.93516}& {169.1262136}& {0.9194599687}& {4.448008452}{×}{{10}}^{{6}}\end{array}\right]{,}\left[\left[{80}{,}{1199}\right]{,}\left[{412}{,}{1742}\right]\right]$ (5)