Cyclomatic Complexity in Software Programming
Software Design is the process to convert the client user requirements into a few reasonable forms which help the developers during the coding and implementation stages. It deals with transforming the client requirements, as described in the SRS (Software Requirement Specification) document, into a form.
Different levels of Software Design:
There are three different levels of software design. They are:
The architecture of a framework can be seen as the overall structure of the framework and the way in which structure gives conceptual astuteness to the framework. The architectural plan recognizes the program as a framework with numerous components of collaboration with each other. At this level, the designers get an idea of the proposed solution.
Preliminary or high-level design:
The high-level plan drills down into the ‘single entity-multiple component’ idea of the architectural plan into an arrangement of sub-systems & modules and portrays their interaction with each other. A high-level plan centers on how the framework, with all of its components, will be interacting with each other. It recognizes the measured structure of each sub-system and their connection and interaction among each other1.
Once the high-level plan is ready, a point by point plan is prepared. In a point by point plan, each module is inspected carefully to plan the information structure and calculations. The organized result is archived within the shape of a module specification document.
Is Software Metrics required?
To improve the quality of software, we need to measure various aspects:
- Maintainability of software among others.
Choosing the correct metrics can make the difference between the success and failure of a project.
The Term complexity stands for the state of occasions or things, which have numerous interconnected joins and exceedingly complicated structures.
Complexity can be interpreted in different ways:
- Issue complexity (moreover called computational complexity) measures the complexity of the basic issue.
- Algorithmic complexity reflects the complexity of the calculation executed to illuminate the issue.
- Auxiliary complexity measures the structure of the program utilized to actualize the calculation.
It basically consists of statements. It is calculated by creating a Control Flow Chart of the code that estimates the number of linearly-independent paths or ways through a program module and it measures the number of straight freeways through a program.
It was developed by McCabe in 1976. If the program’s Cyclomatic Complexity is lower, then it has a lower risk of being subjected to modifications in the future and is also easier to understand.
Determination of Cyclomatic Complexity:
There are several methods:
1. Cyclomatic complexity = edges — nodes + 2 UCP
2. Cyclomatic complexity = Number of PN* + 1
3. Cyclomatic complexity = Number of regions in the CFG*
PN — Predicate Nodes
CFG — Control Flow Graph
Cyclomatic Complexity = Edges –Nodes + 2P
UCP = Number of unconnected parts of the graph.
In the above examples, the Cyclomatic Complexity is calculated based on the (Edges-Nodes +2 PN) formula as 7–8 + 2*2 = 3
Cyclomatic complexity = Number of PN + 1
Cyclomatic Complexity = 2 + 1 = 3
In this Example:
Cyclomatic complexity= Number of PN + 1
Cyclomatic Complexity = 3
In this Example:
Cyclomatic complexity = number of regions in the CFG.
How is the Cyclomatic Complexity Metric useful for QA?
- Basis Path testing is a white box testing technique and it ensures the execution of at slightest one articulation amid testing.
- It checks every single one of the linearly independent paths in the code.
- This means the number of test cases will be equivalent to the cyclomatic complexity of the program.
- From the above table, it can be understood that even a small program logic, when taken as a whole, in combination with other interrelated functions, will have high Cyclomatic complexity. That is the reason why Cyclomatic Complexity is always measured at the function level.
- The Industry-standard is to always keep the Cyclomatic Complexity of each function to below 10.
- The advantage of this is that the function can have a maximum test case count (test cases that deal with the logic behind the specific lines of code) of 10. Research has proven that most computer programmers can effectively be examined and adjust capacities that are having Cyclomatic complexity less than or equal to 10.
- Also, when the cyclomatic complexity is kept less than 10, the cognitive load on the human mind is less.
Uses of Cyclomatic Complexity:
Cyclomatic Complexity can demonstrate to be exceptionally supportive in:
- Helping designers and analyzers to decide free-way executions.
- Designers can guarantee that all the ways have been tried at least once.
- Helps us to center more on the revealed paths. Evaluates the chance related to the application or program.
- It is primarily utilized to assess the complexity of a program.
- If the number of decision points is more, then the Cyclomatic complexity of the code is higher.
- In case the program has a tall complexity number, at that point, the likelihood of a mistake is also high which in turn requires extended time for support and troubleshooting.
Software design level: High-level Design:-
https://www.tutorialspoint.com/software_engineering/software_design_basics.htm Publication date unavailable