Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

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

2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

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)

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report