NAGWare Fortran Tools - f77 Tools - nag_metrics

 

Index

NAME
DESCRIPTION
TABLE LAYOUT OPTIONS
METRICS OPTIONS
USE OF THE TOOL
THE METRICS WHICH ARE CALCULATED
HALSTEAD'S MEASURES
DESCRIPTION OF THE AVAILABLE MEASURES
THE HISTORY OF SOFTWARE METRICS
REFERENCES
RESTRICTIONS
SEE ALSO

 

NAME

nag_metrics - NAGWare f77 Tools Metrics

 

DESCRIPTION

nag_metrics is the NAGWare f77 Tools Fortran 77 complexity measurement tool. This produces a table of the specified metrics. By default a table containing all possible measures, except knots, is produced for the entire program. Optionally output may be restricted to a specified set of measures. Also output for each program unit may be requested.

Metrics consist of measures of the length of the program, for example the number of executable statements, and the complexity of the program, for example McCabe's cyclometric complexity.

 

TABLE LAYOUT OPTIONS

"Global mode" (-global)
If -global is set, the tool operates in global mode. This means that the table of metrics which is returned to the user contains a set of measures which apply to the whole program. The default is -global.

"Parts mode" (-parts)
If the -parts option is specified a table containing the metrics for each program unit will be produced. Both -global and -parts may be specified.

"Expand abbreviations" (-expand)
If the -expand option is specified the table of measures is made clearer by expanding the abbreviated names to more meaningful titles. This results in a longer table where the metrics are output one per line.

 

METRICS OPTIONS

"Statements" (-statements)
When this flag is set the tool will count the number of executable statements.

"Lines" (-lines)
If this option is set the tool counts the number of lines of program code, excluding comments and blank lines and including lines in include files.

"Comments" (-comments)
The -comments flag when set indicates to the tool that the number of comments in the program should be counted.

"Blanks" (-blanks)
If this option is set the number of blank lines is totaled. A blank line is defined as an empty line, a line containing no characters other than spaces and tabs, or a comment line starting with 'C' or 'c' or '*', empty or followed only by white space.

"Halstead" (-halstead)
The -halstead flag when set indicates that the Halstead metrics should be calculated. These are Program Volume, Complexity Level, Effort, Development Time, Number of Bugs. For more details please see "HALSTEAD'S MEASURES".

"McCabe" (-mccabe)
Calculate McCabe's Cyclometric number as defined below. If -global is specified the global table contains the average McCabe's Cyclometric number per program unit.

"Binary Decision" (-binary_decision)
Calculate the number of binary decisions taken throughout the program.

"Absolute Complexity" (-abs_complexity)
The absolute complexity measure, as defined below, will be calculated,

"Knots" (-knots)
Calculate the number of knots in a program.

 

USE OF THE TOOL

The tool comprises three distinct parts which are as follows:

Lexical analysis is run for all metrics except knots. The parse tree analysis is run only for the calculation knots.

 

THE METRICS WHICH ARE CALCULATED

                                              Abbreviation
Number of Executable Statements                  STMTS
Number of lines of code (excluding comments)     LINES
Number of Comments                               CMNTS
Number of Blank Lines (incl. Blank Comments)     BLANK
The Ratio of Comments to Statements              CM/ST
Number of unique operators (Halstead)            ETA_1
Number of unique operands (Halstead)             ETA_2
Number of operators (Halstead)                   N1
Number of operands (Halstead)                    N2
The vocabulary of the program (Halstead)         VOCAB
Program Length                                   LENGTH
Estimate of Program Difficulty                   DIFF'TY
Measure of the Program Volume (Halstead)         VOL
Measure of the Complexity Level (Halstead)       LEVEL
Effort Required to Produce Program (Halstead)    EFFORT
Estimate of the Development Time (Halstead)      DT
Estimated Number of Bugs (Halstead)              BUGS
The McCabe Cyclometric Number                    McCabe
Number of Decisions                              DEC'Ns
Number of Binary Decisions                       BINARY
Estimate of the Absolute Complexity              A.C.

 

HALSTEAD'S MEASURES

Halstead's measures which are described in a his book Elements of Software Science [2] were not based on any particular language and in recent years the measures have been calculated in various languages to see if they correlate. Due to this no general agreement has yet been reached to establish which tokens are operators and which are operands. This has lead to many different interpretations of his measures and thus it should be noted that the nag_metrics tool uses the rules laid out below.

Operators are defined as:

Operands are defined as:

As can be seen from the above definition, the declarative section of a program is completely ignored because it is considered not to add to the complexity of the algorithm due to it not being executable. Thus tokens such as PROGRAM, INTEGER, COMMON, INTRINSIC and DIMENSION are ignored by the tool. The definition of an operand (as in "INTEGER I,X" ) is not counted as a use of an operand.

Tokens such as REWIND or BACKSPACE are not included as operators or operands because they add little to the overall complexity of an algorithm.

The total number of decisions is defined as being the total number of computed and assigned GOTOs plus the number of DO loop plus the number of IF statements plus the number of ELSEIF statements.

The number of statements is defined by the number of executable statements, the number of comments as the number of lines with a "C" or a "c" in the first column. The number of blanks lines is defined as being the number of totally blank lines plus the number of blank comment lines (including lines only containing white space).

 

DESCRIPTION OF THE AVAILABLE MEASURES

Number of Statements

A very basic form of measuring the complexity of the code is to count the number of executable statements in the code. This measure may be used to identify large monolithic program units.

Number of Lines of Code

An alternative measure of the length of the program is the number of statement lines. This includes declarations but excludes comments and blank lines.

Number of Comments

A good piece of software should be well documented throughout, therefore the better the program the more comments the code should contain.

Number of Blank Lines and Blank Comments

As with the number of comments this measure may be used as a measure of the clarity and readability of the code in a piece of software. Good software should be well presented to ease reading and debugging.

The Ratio of Comments to Statements

The comment measure means little on its own but the ratio of comments to statements gives a good measure of the readability and clarity of the code.

Halstead's Measures

To describe Halstead's measures we first need some definitions

Halsteads measures can be summarised as being "size metrics".

Measure of the Program's Volume (Halstead)

The measure of a program's volume is calculated by Halstead in the following way
      V = N * log(n)
where n = n2 + n1 is the program's vocabulary and N is the length of the program (given by N2 + N1) in the code. Note also that the log is to the base 2.

Measure of the Complexity Level (Halstead)

The measure of a program's complexity as defined by Halstead is given by
 L = 2 * n2/(n1*N2)

This can give an overall complexity measure of the program.

Effort Required to Produce Program (Halstead)

Halstead defined this to be
 E = V/L that is (volume/complexity level)
 

Estimate of the Development Time (Halstead)

Development time (in arbitrary time units) can be calculated as follows:


 T = E/S (where S is Strouds number (18))

Estimated Number of Bugs (Halstead)

Halstead defined this measure to be


 B = E^(2/3)/3000

The McCabe Cyclometric Number

McCabe described a way of measuring a program's complexity by it logical structure. It is probably still one of the most widely used and popular of all the metrics available today. Its simplicity is due to the way that it is calculated, this can be done in one of two ways


 v(G) = e - n + 2

where v(G) is the cyclometric complexity of the flow graph (G) for the program in question and e is the number of edges in G and n is the number of nodes. or


 v(G) = DE + 1

where DE is the number of binary decisions made throughout the program.

In the TOTALS row of the table (if -global option is specified) the total McCabe's number is divided by the number of program units to give the average, rounded to the nearest integer.

Number of Binary Decisions

A binary decision is defined as being an arithmetic IF in which two labels are identical, a logical IF, a block IF with no following ELSEIF and an optional following ELSE clause, a computed or assigned GOTO with only two possible outcomes or a DO loop.
 

Estimate of the Absolute Complexity

The absolute complexity of a program is defined to be the number of binary decisions divided by the number of statements.

 

THE HISTORY OF SOFTWARE METRICS

Today there are many ways of measuring the complexity of a program, the measures included in this tool are typical of those which have been developed over the past few years.

Software complexity is a way of identifying, classifying and measuring various features and characteristics of a piece of code which may when considered lead to changes in code which will ultimately lead to better code and lower the lifetime cost of the product.

The first major paper published on the subject was in 1976 by McCabe[1] with his description of a measure for the cyclometric complexity of a program, a very simple measure to calculate.

Shortly afterwards in 1977 a book published by Halstead [2] described ways of calculating new measures which analysed the structure of software in more detail and allowed the calculation of development time and costs. Measures which were described in the paper are still the basis for the Software Metrics we have today.

Since Halstead published his paper many others have developed his work and created new ways of measuring the complexity of software, however it wasn't until the mid 1980's that the use of Software metrics in the computing industry started. This can be said to be attributed to software houses finding that maintainance of existing software was taking up, in many cases, over 70% of their budget. With this in mind it was clear that if the complexity of programs could be dramaticly reduced, the price of maintainance could be cut. Software Metrics are an easy way of assessing the complexity of software as development takes place.

The measure of "Knots" in software has also been included in this tool which has its basis in a paper published in 1979 [3]. If a piece of code has arrowed lines indicating where every jump in the flow of control occurs, a knot is defined as where two such lines cross each other. The number of knots is proportional to the complexity of the control flow.

Many other papers have been written on the subject of metrics which can not all be recorded here, but it is worth note that a bibliography published in Software Engineering Notes Volume 12[4] has a very clear and concise list of the papers associated with this subject.

 

REFERENCES

[1] - McCabe, T.J. A Complexity Measure, IEEE Transactions on Software Engineering, Vol. SE-2, 308-320(1976).

[2] - Halstead, M.H. Elements of Software Engineering, Elsevier, New York(1977).

[3] - Woodward, M.R. et al. A Measure of Control Flow Complexity in Program Text, IEEE Transactions in Software Engineering, Vol. SE-5, 45-48(1979).

[4] - Waguespack, L.J. Badlani, S. Software Complexity Assessment: An Introduction and Annotated Bibliography, Software Engineering Notes, Vol. 12 no.4 pp.52-70(1987).

 

RESTRICTIONS

nag_metrics recognises the ANSI standard Fortran 77 intrinsic functions, the US Military Standard intrinsic functions, and the double complex intrinsics defined in nag_Fortran77.

nag_metrics may produce inaccurate results if the total program is not supplied. No warning will be given.

nag_metrics works on a garbage in garbage out basis if the parsing stage is not executed. It is advised that the program is first run though nag_pfort before executing the metrics tool to ensure that the code is legitimate Fortran 77.

 

SEE ALSO

nag_Fortran77, nag_pfort, nag_transformers

Copyright, Numerical Algorithms Group, Oxford, 1991-2001