13.07.2015 Views

An Analysis of the Design and Definitions of Halstead's Metrics

An Analysis of the Design and Definitions of Halstead's Metrics

An Analysis of the Design and Definitions of Halstead's Metrics

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

n 1 : Number <strong>of</strong> distinct operators.n 2 : Number <strong>of</strong> distinct oper<strong>and</strong>s.N 1 : Total number <strong>of</strong> occurrences <strong>of</strong> operators.N 2 : Total number <strong>of</strong> occurrences <strong>of</strong> oper<strong>and</strong>s.In addition to <strong>the</strong> above, Halstead defines [3]:n * 1 : Number <strong>of</strong> potential operators.n * 2 : Number <strong>of</strong> potential oper<strong>and</strong>s.Halstead refers to n * 1 <strong>and</strong> n * 2 as <strong>the</strong> minimumpossible number <strong>of</strong> operators <strong>and</strong> oper<strong>and</strong>s for amodule or a program respectively. This minimumnumber would occur in a programming languageitself, in which <strong>the</strong> required operation already existed(for example, in C language, any program mustcontain at least <strong>the</strong> definition <strong>of</strong> <strong>the</strong> function main()),possibly as a function or as a procedure; in such acase, n * 1 =2, since at least two operators must appearfor any function or procedure: one for <strong>the</strong> name <strong>of</strong> <strong>the</strong>function <strong>and</strong> one to serve as an assignment orgrouping symbol. Next, n * 2 represents <strong>the</strong> number <strong>of</strong>parameters, without repetition, which would need tobe passed on to <strong>the</strong> function or <strong>the</strong> procedure [14].All <strong>of</strong> <strong>the</strong> <strong>Halstead's</strong> so called "S<strong>of</strong>tware Science"metrics are defined based on <strong>the</strong> above collectivemeasures (n 1 , n 2 , N 1 , N 2 , n * 1 <strong>and</strong> n * 2 ).Halstead defines <strong>the</strong> following metrics [3]:- The length (N) <strong>of</strong> a program P is:N = N1 + N 2.(1)- The vocabulary (n) <strong>of</strong> a program P is:n = n1 + n 2.(2)- Program volume (V) is defined by Halstead inhis book as:a) a suitable metric for <strong>the</strong> size <strong>of</strong> anyimplementation <strong>of</strong> any algorithm; 1b) a count <strong>of</strong> <strong>the</strong> number <strong>of</strong> mentalcomparisons required to generate aprogram. 2V can be computed using <strong>the</strong> followingequation:V = N *log2 n.(3)The length, <strong>the</strong> vocabulary <strong>and</strong> volume <strong>of</strong> aprogram are considered as reflecting differentviews <strong>of</strong> program size [15].- Program potential (minimal) volume (V * ), whichis <strong>the</strong> volume <strong>of</strong> <strong>the</strong> minimal sizeimplementation <strong>of</strong> a program P, is defined as 3 :1 Halstead’s book [3], p. 19.2 Halstead’s book [3], p. 47.3 No objective evidence documented in [3] that this isindeed a minimal implementation.V*= (2 + n*) log (2 + n* 2 2 2 ). (4)- Program level (L) <strong>of</strong> a program P with volume Vis:V*L = .(5)VThe program level emphasizes that growth involume leads to a lower level <strong>of</strong> program, <strong>and</strong>conversely. The largest value for L is 1. Inaddition, this value is interpreted as referring to<strong>the</strong> most ideally written program <strong>and</strong> asmeasuring how well written a program is. Thus,programs with L values close to 1 areconsidered to be well written, in general L

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!