_COMPLEX Complexity Report

Top  Previous  Next

 

Targets: All

 

Complexity per module/subprogram

 

This section lists a number of important metrics:

 

Total Lines

Lines of Code (LOC)

Comment Lines

Comments/Total Lines

Comments/Lines of Code (Comments/LOC)

Decision Points (DP)

Decision Points/Lines of Code (DP/LOC)

Characters/Lines of Code (Chrs/LOC)

Comment Characters/Characters

 

 

These metrics will help you evaluate source code in terms of understandability, complexity, and reusability. Complex code is harder to maintain and is more error prone. You can also locate complex subprograms that would be better split up.

 

Minimizing complexity is a major key to writing high quality code. Measure the complexity regularly during development so complex code can be identified early and rewritten to improve understanding and to reduce testing and future maintenance effort.

 

Results are also calculated for code from different source folders. Each folder generates one set of data. In this way, you can compare for instance code from different third-party toolkits that are located in different folders.

 

For these metrics, only source code files are counted, so for instance DFM files are not included.
 

Total Lines are all lines, including blank lines and comment lines.
 

Lines of Code are lines, excluding blank lines and full comment lines that contain actual code. For a subprogram (procedure/function) this is the code part including lines with begin/end.
 

Comment Lines are comment lines or lines that are partly commented.
 

Decision points is equivalent to McCabe’s metric, or cyclometric complexity. These are all well-known metrics in the software industry that are used to estimate code complexity. Decision points are positive integers where increasing values mean a higher degree of complexity. It is calculated by PAL in this way:

 

1. Start with a value of 1 for the normal flow through a subprogram.

2. Add 1 for each of these keywords: IF, WHILE, REPEAT, FOR, AND, OR, XOR, GOTO. Note that PAL always counts AND, OR, XOR, even if they are used as arithmetic operators in the actual code.

3. Add 1 for each case label in a CASE statement. When the CASE does not have an ELSE, add 1 more.

 

A normal interpretation of decision points is that you should try to break routines with a value of 10 or more into smaller pieces.

 

Decision Points/Lines of Code is just an average of the DP over the lines of code.

 

Characters/Lines of Code is an average of characters over lines of code.

 

Comment Characters/Characters is an average of comment characters over total characters. All comment characters including leading and trailing white space (beginning and end lines) are accounted for, plus the comment tokens themselves.

 

Example:

 

{ this is a comment }

 

This comment has 21 characters

 

// another one

 

This comment has 14 characters

 

{this

comment is on

multiple

lines}

 

This comment has a total of 32 characters

 

This is an excerpt from a complexity report:

 

****************************************************************************

*                          Complexity Report for                           *

*                      C:\PROJEKT\PSEARCH\PSEARCH.DPR                      *

****************************************************************************

 

Abbreviations: C=Constructor  D=Destructor  F=Function

              FM=Function (method)  MB=Program main block

              P=Procedure  PM=Procedure (method)

              UF=Unit finalization  UI=Unit initialization

 

Module/Subprogram                         Total    LOC    Cmt  Cmts/     DP    DP/  Chrs/

                                         Lines         Lines  Total           LOC    LOC

                                                              Lines            

 

Overall                                     715    436    132   0,18     46   0,11      1

 

psearch                                      14     10      1   0,07      1   0,10     20

 psearch (MB)                                5      5      0   0,00      1   0,20     19

 

psform                                      701    426    131   0,19     45   0,11     26

 TPSMainForm.chkAllFilesClick (PM)           5      4      0   0,00      2   0,50     12

 TPSMainForm.CmdQuitClick (PM)               4      3      0   0,00      1   0,33      5

 TPSMainForm.CmdSaveClick (PM)              13     11      0   0,00      2   0,18     14

 TPSMainForm.CmdSearchClick (PM)            55     42      0   0,00      9   0,21     19

 TPSMainForm.CmdSelStartDirClick (PM)        8      6      0   0,00      2   0,33     28

 TPSMainForm.CmdSpecial1Click (PM)         104     53     29   0,28      3   0,06     30

 TPSMainForm.CmdSpecial2Click (PM)         130     96      2   0,02     13   0,14     21

 

 

Even if it may seem simple, lines of code is quite a good measure of how complex a program is. Decision points (DP) also provide a good indication.

 

Be forewarned that the Complexity Report may take relatively long time to generate, compared with the other reports.

 

It is possible to sort this section according to any of the keys, like Total Lines, LOC, DP etc.

 

 

Long identifier names

 

PAL also creates a list of all identifiers with names that are longer or equal to 15 (default) characters in length. You can select the identifier length, for which PAL will start reporting. E.g. if you select 20, PAL will report all identifiers having 20 or more identifiers.

 

The remaining sections in the Complexity Report show different lists. These list rate modules, subprograms and classes by varying criteria, like most lines of code (LOC). Optionally, if HTML reports are created, a chart can be generated for each section. The charts are saved as image files (JPG) in the report folder.

 

This is a sample of a chart illustrating Largest Modules by Total Lines:

 

 

These sections show statistics:

 

Largest Modules by Total Lines

Largest Modules by LOC

Most Complex Modules by DP

Most Complex Modules by DP/LOC

Most Complex Modules by Characters per LOC

Most Commented Modules by Comment Lines

Most Commented Modules by Comment Lines per Total Lines

Most Commented Modules by Comment Lines per LOC

Most Commented Modules by Comment Characters per Total Characters

 

Largest Subprograms by Total Lines

Largest Subprograms by LOC

Most Complex Subprograms by DP

Most Complex Subprograms by DP/LOC

Most Complex Subprograms by Characters per LOC

Most Commented Subprograms by Comment Lines

Most Commented Subprograms by Comment Lines per Total Lines

Most Commented Subprograms by Comment Lines per LOC

Most Commented Subprograms by Comment Characters per Total Characters

 

Most Methods per Class

Most Fields per Class

Most Properties per Class

Most Parameters per Subprogram

 

 

See also:

 

R_METRIC Metrics Reports