The loop complexity of the code (cyclomatic complexity, where it translates into cyclomatic complexity) is a measure of code complexity, presented by Thomas J. McCabe, Sr., in 1976.
In the concept of software testing, cyclomatic complexity is used to measure the complexity of a module to determine the structure, the number of which is represented by the number of independent linear path, that is, reasonable prevention of errors required to test the minimum number of paths. Large Cyclomatic complexity indicates that the program code may be of low quality and difficult to test and maintain.
Calculation formula
Ring complexity = E? N + 2
E = number of edges in the program control flow graph
N = number of midpoint in the program control flow graph
Look at a concrete example. The ring complexity of the ABAP code below is calculated as 3 according to the formula.
DATA: lv_value TYPE i VALUE 1. IF lv_value = 1. WRITE: / ‘always happend‘. ELSEIF lv_value = 2. WRITE: / ‘not possible‘. ELSE. WRITE: / ‘even not possible‘. ENDIF.
Let's start by drawing out the program flow of the code:
Use the Code Inspector tool in ABAP to measure the loop complexity of the codes:
Refer to my ABAP blog for specific steps:
Java can measure the ring complexity with a tool called Sourcemonitor:
Refer to my blog for details using Sourcemonitor to monitor your Java code complexity
To get more original Jerry's technical articles, please follow the public number "Wang Zixi" or scan the QR code below:
How to calculate and measure the ring complexity of ABAP and Java code cyclomatic complexity