SoftwareMetrics - Maple Programming Help

# Online Help

###### All Products    Maple    MapleSim

Home : Support : Online Help : Programming : Packages : SoftwareMetrics Package : SoftwareMetrics/HalsteadMetrics

SoftwareMetrics

 HalsteadMetrics
 compute Halstead's software science metrics

 Calling Sequence HalsteadMetrics(prc, sm)

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{1}{2}\frac{\mathrm{n1}\mathrm{N2}}{\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}}& \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]\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}}& \left[\begin{array}{cccccc}{156}& {402}& {2928.731692}& {48.22222222}& {1.259462226}& {1.412299505}{}{{10}}^{{5}}\end{array}\right]& \left[\left[{48}{,}{185}\right]{,}\left[{108}{,}{217}\right]\right]\\ {\mathrm{dsolve/numeric}}& \left[\begin{array}{cccccc}{565}& {2777}& {25387.63130}& {148.5188285}& {1.150957143}& {3.770541259}{}{{10}}^{{6}}\end{array}\right]& \left[\left[{87}{,}{1145}\right]{,}\left[{478}{,}{1632}\right]\right]\end{array}\right]$ (3)
 > $\mathrm{HalsteadMetrics}\left('\mathrm{CurveFitting}'\right)$
 $\left[\begin{array}{c}{\mathrm{1..12 x 1..3}}{\mathrm{Array}}\\ {\mathrm{Data Type:}}{\mathrm{anything}}\\ {\mathrm{Storage:}}{\mathrm{rectangular}}\\ {\mathrm{Order:}}{\mathrm{Fortran_order}}\end{array}\right]$ (4)
 > $\mathrm{HalsteadMetrics}\left('\mathrm{CurveFitting}','\mathrm{summarize}'\right)$
 $\left[\begin{array}{cccccc}{456}& {2960}& {26145.35444}& {172.9000000}& {0.8745900802}& {4.520531783}{}{{10}}^{{6}}\end{array}\right]{,}\left[\left[{76}{,}{1231}\right]{,}\left[{380}{,}{1729}\right]\right]$ (5)

 See Also

## Was this information helpful?

 Please add your Comment (Optional) E-mail Address (Optional) What is ? This question helps us to combat spam