The Software Metrics Module

In this context, software metrics means a set of measurements made of the source code of your program to determine certain metrics or ratios. This is a domain with a long story of continuous refinement of the definitions and metrics involved that would be impossible to describe in the context of a software manual. It is this author’s personal opinion, however, that this field has lacked the raw data from numerous measurements by many people. With this idea in mind, Wedit tries to provide you with a set of tools to measure your code and deduce your own conclusions. The emphasis is on providing raw data and displaying it without any interpretation; the objective being that you interpret the measurements as you like. Important here are not the actual numbers displayed, but the experience you accumulate by investigating your own code and seeing how those numbers correlate to your experience with the software that you write or maintain.

After reviewing the enormous amount of papers published within this field, the author abstracted the following information, which seems to be widely recognized as meaningful measurements.

           The number of lines of a program/module

           The number of unique operands

           The total number of operands used

           The number of unique operators

           The total number of operators

           The number of flow control statements

           The volume of commentaries

For the C language, Wedit considers the expression "++" or "+=" as an operator. Constants and variables are considered as operands (the objects that operators manipulate). A construct such as 'while' or 'for' is considered to be a control flow directive.

Analysis of a Whole File

This option provides a global view of the functions in a file, displaying the results in a graphical form. You can call up this option by clicking somewhere in an open file with the right mouse button. In the contextual menu that opens, choose the ‘metrics’ menu option.

A line whose length is proportional to its length or volume, depending on the settings of the ‘Data’ menu selection represents each function in the file. To see to which function each line corresponds to, click on the line you are interested in. In the dialog box (at the bottom of the graphic), this will display the exact value of the line and the name of the function to which it corresponds. If you select it in the dialog box, all the data corresponding to the data will be shown.

 

The result is displayed in the following dialog box:

There are four main groups of collected data:

           The group to the left shows the raw data.

           The 'Style' group shows the percentage of comments, etc.

           The 'metrics' groups show the values calculated according to the formulae below.

           The 'Identifiers' list appears as information only.

The formulae used are:

 

LENGTH: Total number of operators + total number of operands

VOLUME: Length * (log(number of unique operands)/log(2) )

LEVEL:    (2 / unique operands) * (unique operands / total number of operands)

DENSITY: VOLUME / LEVEL

These formulae correspond to Halstead’s work.

 

How Wedit Collects the Data

It is not necessary in this forum to discuss at length what a line of code is. Defining the nature of an instruction, is slightly more complicated. For the C language, Wedit uses the number of statement separators (the semi-colon) as a guide. The other definitions are straightforward: All operators are counted for the number of possible operators, including the preprocessor commands. The rationale behind this is that they count for the comprehension of the text. Parentheses are counted each as an operator.

Numbers are considered operands, as well as static character constants or strings. The flow-control operations such as, 'for case while', etc. are counted, and they are important for the McCabe complexity measurement.

The 'style' group gives the percentage of comments, the number of 'goto' instructions used, and the maximum depth of blocks in the analyzed code.