Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use the tool Source Monitor to measure the ring complexity of Java code

Shulou Source: shulou.com Published: 2022-06-02 09:23:53 10月03日 Update

This article mainly shows you "how to use the tool Source Monitor to measure the ring complexity of Java code", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "how to use the tool Source Monitor to measure the ring complexity of Java code" this article.

Cyclomatic complexity (sometimes translated into cyclomatic complexity) is a measure of code complexity, which was developed by Thomas J. McCabe, Sr in 1976. Put forward.

Let's take a look at the formula.

Code loop complexity = E − N + 2

E = the number of edges in the program control flow graph

N = the number of points in the program control flow graph

It is easy to conclude that the higher the complexity of the code loop, the easier it is to produce bug.

It is conceivable that if developers are required to draw the control flow diagram of a piece of code and then count the number of edges and points in the diagram, this is too inefficient and error-prone.

The good news is that there is a free software called Source Monitor that can help us measure the ring complexity of Java code. Of course, the software also supports C++ and C#.

To show how to use this software, I wrote a simple piece of Java code.

Package test;import java.util.ArrayList;public class monthTool {static ArrayList monthCollection = new ArrayList (); public static void main (String [] args) {monthTool tool = new monthTool (); tool.printV1 (1); tool.printV2 (2); tool.printV1 (0); tool.printV2 (- 1); tool.printV3 (3); tool.printV3 (13);} public monthTool () {monthCollection.add ("Invalid"); monthCollection.add ("January"); monthCollection.add ("Febrary"); monthCollection.add ("March") MonthCollection.add ("April"); monthCollection.add ("May"); monthCollection.add ("June"); monthCollection.add ("July"); monthCollection.add ("August"); monthCollection.add ("September"); monthCollection.add ("October"); monthCollection.add ("November"); monthCollection.add ("December"); public void printV1 (int month) {System.out.println ("Month is:" + getMonthNameV1 (month));} public void printV2 (int month) {if (month > = 1 & month & month)

Tags: Complexity complexity code method scale file month tool measurement number representative content name article software project diagram control different way Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS Docker NVidia Huawei Apple