Software complexity Overview

Source: Internet
Author: User

Complexity

In 1970s, software systems had become extremely complex, and both development and maintenance were costly. People realize that software must be modularized for development, testing and maintenance. Therefore, McCabe & Associates, founded in 1976, developed the McCabe cyclomatic complexity metric technology to test the software structure. Metric, based on the number of software complexity measurements, helps engineers identify modules that are difficult to test and maintain. The complexity of the circle has become an important criterion for evaluating software quality. People can use the circle complexity to measure the software complexity and quality, arrange the project progress, and seek a balance between the cost, progress, and performance.

In the design of hardware reliability, there is a basic principle: "Simplicity is reliability ". This principle is also suitable for software. With the increase or enhancement of functions, software is constantly upgraded and patched. There are already several methods to measure the complexity of software for reference. Among them, McCabe QA is an excellent and practical method that can calculate the complexity of various software, this allows you to inspect, analyze, and identify software that may cause errors.Code

 

Complexity

Modules, classes, andProgramThree types of complexity. The module complexity includes information about the complexity of the module. The class complexity is usedThe McCabe object-oriented program contains information about the complexity of the class, and the complexity of the program contains information about the complexity of the program.

Integrated complexity report

Three complexity reports correspond to the three complexity reports. If there is more than one type of complexity information in a report, the complexity information is combined into a new report.

The integration complexity information only collects information of one component and its subordinates. For example, if a program-Level Report contains a class complexity, only information about the classes that comprise the program is reported, but not information about the classes.

 McCabe complexity

McCabe complexity is obtained by strictly performing Arithmetic Analysis on the software structure. In fact, it is a measure of the complexity of the program topology structure and clearly points out the complex part of the task. The McCabe complexity includes: Circle complexity, basic complexity, module design complexity, design complexity, integration complexity, number of rows, standardization complexity, global data complexity, local data complexity, and pathological data complexity.

Use of McCabe complexity

Three methods are available in software engineering.McCabe complexity measurement method.

As an auxiliary tool for testing.The result of the McCabe complexity measurement is equal to the number of paths passing through a sub-program. Therefore, you need to design the same number of test cases to overwrite all paths. If the number of test cases is smaller than the number of complexity, you can perform more tests in three cases: one is to perform more tests, the other is to remove some judgment points, and the other is to replace some judgment points with plug-in code.

Serves as a guide to programming and management. In software development, a simple method is required to point out subprograms that may cause problems. A general method to keep the subroutine simple is to set a length limit, for example50 rows or two pages, but this is actually an alternative to the lack of a testing method that is concise and effective. Many people think that McCabe measurement is such a simple measurement. However, it should be noted that the McCabe measurement program is not structured as well. For example, the case statement has a good structure, but there may be a large number of McCabe measurements (dependent on the number of branches in the statement ), this may be determined by the complexity inherent in the problem and solution. The user should decide on how to use the information provided by McCabe measurement.

As a measure of network complexity.Hall and preiser propose a Composite Network Complexity Measure to measure the complexity of a large software system that may be created by multiple programmer groups based on Modular principles. Their combined measurement formula is

FormulaC1,..., CK is the complexity of each module; CN is the network complexity; W1 and W2 are the weights.

McCabe complexity can be used to measure the complexity of each module or network complexity.

 Cyclomatic complexity (V (G) circle complexity

The circle complexity is used to measure the complexity of a module's decision structure. The number is represented by the number of independent paths, that is, the minimum number of paths required for testing to properly prevent errors, large circle complexity indicates that the program code may be of low quality and difficult to test and maintain. Experience shows that program errors and high circle complexity are closely related.

Calculation Method

A node is the smallest unit of code in a program. An edge represents the program flow between nodes. If a module flow chart hasE is an edge with N nodes. The circle complexity is V (G) = E-N + 2, and the typical V (G) max is 10. In Figure 1, the complexity of the circle is 2.

Advantages

Avoid mistakes in software; point out extremely complex modules, such modules may be further refined; measure test plans and determine test priorities; and guide the test process by limiting program logic during development; identifies the region to be tested, helps testers determine test and maintenance objects, and is independent of the Advanced Programming Language type used.

Application

Circle complexity indicates the minimum number of basic paths to ensure software quality. In practice, it is unrealistic to test each route, and the test difficulty increases with the increase of the path. However, the basic test path is necessary to measure the rationality of Code complexity.McCabe & Associates recommends that the circle complexity be 10, because the high circle complexity makes the test more complex and increases the probability of software errors.

Tip:

The circle complexity measurement is used to measure the number of branches in a software module during all development cycles.

The circle complexity measurement is based on the software structure flowchart. The control flowchart describes the logical structure of the software module. A module is a function or subroutine in a typical language. It has an entry and an exit./Return mechanism design module. Each execution path of the software module corresponds to the entry-to-exit node in the control flowchart of the module.

"Cyclomatic "is derived from the number of non-directly connected basic test cycles. More importantly, the number of independent paths is also given through directly connected charts. By correlation of charts, one node can reach another node.

The circle complexity measurement can also be used as the number of paths in the module's basic flowchart. The focus is that after the linear combination of modules, the number of paths generated is the smallest.

Limitations on sphere complexity

There are many good ways to limit the complexity of the circle. Modules that are too complex are prone to errors and difficult to understand, test, and correct. Therefore, complexity should be consciously restricted at all stages of software development, many developers have successfully implemented the restriction on software complexity as part of a software project, despite a slight controversy over the exact number. The initial supported quantity is10, now supports up to 15. However, the number should be greater than 10 only when conditions are good. For example, developers are very experienced and the design conforms to the formal standards, use modern programming languages, structured programs, code pre-arrangement, and advanced testing plans. In other words, the development team can select a limit of more than 10, but it must make trade-offs based on experience and focus on complicated modules.

 Essential complexity (eV (G) Basic complexity

The basic complexity is used to measure the degree of unstructured program. The unstructured components reduce the quality of the program, increase the difficulty of code maintenance, and make the program difficult to understand. Therefore, the high complexity means a high degree of unstructured data, which is difficult to modularize and maintain. In fact, eliminating an error sometimes causes other errors.

Calculation Method

The structured part of the circle complexity diagram is simplified into a point. After the computation is simplified, the circle complexity of the flowchart is the basic complexity.

Advantages

Measure the degree of non-structuring, reflect the quality of the Code, predict the amount of code maintenance, assist module division, and have nothing to do with the type of advanced programming language used.

Application

When the basic complexity is1. This module is fully structured. When the basic complexity is greater than 1 and less than the lap complexity, this module is partially structured. When the basic complexity is equal to the lap complexity, this module is completely unstructured.

 Module design complexity (IV (G) module design complexity

The module design complexity is used to measure the module decision structure, that is, the call relationship between the module and other modules. High complexity of software module design means high coupling of modules, which makes it difficult to isolate, maintain and reuse modules.

Calculation Method

The complexity of the module design is the complexity of the circle obtained from the module flowchart that does not include the decision of calling sub-modules and the cycle structure. Therefore, the complexity of the module design cannot be greater than that of the circle, generally, it is much smaller than the complexity of the circle.

Advantages

Measure the module's dominance over its lower-layer modules; measure the minimum number of integration tests from a module to its sub-modules; locate unnecessary code; and differentiate modules with complex computing logic and design; is the design complexity (S0) and the basis of integrated complexity (S1) computing, independent of the type of advanced programming language used.

 Design complexity (S0) design complexity

Design complexity measures the interaction between program modules by quantity. It provides an overview of the complexity of system-level module design and helps to measure the effectiveness of bottom-up integration testing, it also provides data that comprehensively measures the specification and complexity of the program design, and does not reflect the internal situation of the independent module. A system with high design complexity means that each part of the system has a complex relationship with each other, making it difficult to maintain the system.

S0 is the sum of the design complexity of all modules in the program. The calculation formula is as follows:

 Advantages

It can be applied to complete software or any subsystem, to measure the quality of code, and to point out the overall complexity of a module, reflecting the control relationship between each module and its internal modules; reveals the complexity of module calls in the program and facilitates the computation of integration complexity.

 Integration complexity (S1) Integration complexity

The integration complexity is expressed by the number of integration tests required to prevent errors. Another argument is the number of independent linear Subtrees in the program, A subtree is a sequence of returned calls. Just like the number of test paths, the complexity of integration is the independent linear subtree of a program or its subsystem.

Calculation Method

The integration complexity of a program is very similar to that of a module. You must calculate the number of integrated tests required for a complete test of the program.S1 calculation formula:

S1 = S0-N + 1

N is the number of modules in the program.

Advantages

It facilitates the implementation of integration testing, quantifies the integration testing work and reflects the complexity of the system design, and helps isolate the system complexity as a whole.

 Number of lines (NL) rows

The number of rows is the total number of lines in the module, including code and comments.

Advantages:

The computation is simple. It has nothing to do with the type of the advanced programming language used. It points out the number of lines of the module (that is, the size of the module), which is easy to understand and maintain.

 Normalized complexity (NV) Normalization complexity

The normalization complexity is divided by the number of rows.

Calculation Method

NV = V (G)/NL

Advantages

It has nothing to do with the type of the advanced programming language used; defines those modules with a significant determining logic density. These modules require more maintenance than other common specification modules.

 Global data complexity (gdv (G) Global Data complexity

Global data complexity (requiredMcCabe data quantizes the relationship between the module structure and global data variables. It illustrates the dependence of the module on external data and measures global data testing, it also describes the coupling relationship between modules, which can reflect potential maintenance problems.

For more information on how to track global data usage, see 《McCabe data in using McCabe IQ add-ons.

 Specified data complexity (SDV (G) local data complexity

Local Data complexity (requiresMcCabe data) quantizes the relationship between the module structure and the user's local data variables, and measures the test of local data.

We can useThe McCabe data Data Dictionary selects a separate data element, indicating the specific data type of each data element. The local data complexity also provides other data selection criteria to quantify the impact of the corresponding data in each module on the module control structure.

For more information about data dictionaries, see 《McCabe data in using McCabe IQ add-ons.

 Pathological complexity (PV (G) pathological data complexity

The complexity of pathological data measures the extent to which a module contains completely unstructured components, marking the problematic code that jumps into the loop. These parts have the highest risk and usually need to be redesigned.

Calculation Method

All the non-structured parts, except the structure that jumps into the loop, are converted to a line structure. The pathological complexity is equivalent to the complexity of the loop of the flow chart after simplification.

Advantages

It has nothing to do with the types of advanced programming languages used. It points out reliability issues, reduces maintenance risks, and helps identify extremely unreliable software.

Halstead metrics (halstead complexity)

McCabe QA can generate Halstead metrics complexity for the selected language. Halstead complexity is based on the operators and operators in the program as the counting objects, and the number of times they appear as the counting targets (direct measurement indicators), and then the program capacity and workload are calculated.

Advantages

Do not perform in-depth analysis on the program structure; be able to predict the error rate; predict the maintenance workload; facilitate project planning, measure the complexity of all programs; make the calculation method simple; have nothing to do with the type of advanced programming language used; many research structures show thatHalstead complexity is useful for predicting program work plans and program bugs.

 Line count complexity describes the complexity of line count and lists their advantages.

Line count metrics (line count complexity)

Advantages

Measure the physical scale of software.Line count data, such as comment rows and empty rows; helps identify difficult modules.

Source: Today's electronic Author: Beijing Zhuji

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.