development. In short we can define software metrics as âThe method which deals with the measurement of the software product and the process by which it is ...
Implementing Software Product Metrics in Procedural Paradigm: LOC and Cyclomatic Complexity Metrics Garima Verma* Dr. M.P. Thapaliyal**
ABSTRACT Software metrics are the measures of software and its specifications. The software metrics are the software management techniques which can help us to plan and predict the software development. Information gained by the software metrics can be used in the management and control of the development process to improve the results. In this paper we discuss software product metrics especially for programming paradigm. Software product metrics are the measures of software product from the development process till the installation. Product metrics measure the size of the software, complexity of the software design and quality of the products. Here, we have discussed Lines of code and Cyclomatic Complexity metrics and the method of measurement. Key words: Software metrics, Software product metrics, Cyclomatic Complexity, Lines of Code. 1.
Introduction
Software metrics are the measures of software and its specifications. In the whole process of software development the basic objective of programmer is to design a software which should be developed in an appropriate time schedule, should be cost effective, and must have high productivity. To achieve all these, effective software management is required. Software metrics are the software management techniques which can help us to plan and predict the software development. In short we can define software metrics as “The method which deals with the measurement of the software product and the process by which it is developed.” Or “A quantitative measure of the degree to which a system, component, or process possesses a given attribute” - IEEE Standard Glossary. Information gained by the software metrics can be used in the management and control of the development process to improve the results. Good software metrics should provide the development of models that are capable of predicting process or product parameters which are affecting the software performance and quality. The ideal software metrics should have the
following properties ?
Simple- It should be simple and clear in the objective.
?
Easy- Evaluation method should be easy and obtainable.
?
Robust- It should be insensitive to the changes in the development process and product.
Generally, software metrics can be classified in two categories: Software product metrics and software process metrics. Software product metrics are the measure of software product from the development process till the installation. Product metrics measure the size of the software, complexity of the software design etc. On the other hand software process metrics are the measure of the effort required to design a software system which can be influenced by how the software is designed, overall development time, type of methodology used etc. The software design and development process is similar to the development and design of any vehicle like scooter or bike or car in which engine chassis, clutch, brake and other parts are attached to influence
*Sr. lecturer, MCA Department, Dehradun Institute of Technology, Dehradun **Reader, Garhwal University, Srinagar
"Pragyaan : Information Technology" Volume 7 : Issue 1, June 2009
15
Implementing Software Product Metrics in procedural Paradigm:
the quality and throughput of the vehicle. Similarly the design of modules and the individual control flow and attachment of these modules with main program influence the quality of the software. By using software metrics, programmer can improve the software product quality and throughput. The designing of software depends on two types of programming paradigms Procedural and Object Oriented. The programming language such as C, Pascal supports procedural paradigm where the main focus is to break programming task into number of variables, data structures and functions, where as languages like Java, C# supports Object Oriented paradigm where the focus is to break programming task into objects. Accordingly software metrics for these two different programming paradigms are different. In this paper we discuss product metrics used only for procedural paradigm for size measurement and complexity. 2.
3.
Metrics used in Procedural structures
3.1. Lines of Code (LOC) Metrics This metrics is used to measure the size of the program by counting number of lines in the function or module. It is used to predict how much effort will be required to develop a program. There are various methods to measure the size of the function, therefore it is controversial but still widely used by the software developers. In some cases Lines of code metrics calculated by counting total number of lines including comment lines, blanks in the modules and logical lines (for, if, else etc). However in some cases comment lines, blank lines and logical line of codes are not considered. The type of lines counting method totally depends on the developers. (Boehm 1981) Example: if we consider following code main(void) {
Product Metrics
printf("Hello World");
Product metrics are the measure of software products which are used to measure size, complexity and quality of the product. Generally used size metrics are Line of code metrics, and function point metrics. To measure the complexity of program, metrics used are Cyclomatic complexity metrics, Knots, Information flow metrics. To measure quality factors of the software like correctness, efficiency, portability, reliability etc., product metrics used are Defect metrics, reliability metrics, maintainability metrics etc.
} 1.
Lines of code: 4 (if all lines are considered )
2.
Lines of code: 1 (if only lines ending with semicolon are considered)
3. 2. Cyclomatic Complexity (CC)Metrics This metrics introduced by Thomas McCabe (1976), is used to measure the structural complexity of a function.This metric is calculated by a number of methods. a) By drawing control flow graph of the function. CC can be calculated from the graph by using two formulas-
Software product metrics
(i)
CC= e-n+2
Where, CC- Cyclomatic Complexity
Size metrics
Complexity metrics
Quality metrics
e is number of edges in the graph n- is number of vertices in the graph
LOC Function point CC Knots Information flow Defect Reliability Maintainability Figure 1 - Software Product Metrics
16
(ii)
CC = number of enclosed regions +1
b) By counting all the decision points and logical operations such as if, else, while, for, AND, OR etc. plus one.
"Pragyaan : Information Technology" Volume 7 : Issue 1, June 2009
Institute of Management Studies, Dehradun
CC= no. of decision points +1 4.
q.front=q.rear=0; clrscr();
Impact of CC values in testing
Level of programming risk according to the CC values is shown in Table 1.
3
Table 1. Programming Risk and CC Values
4
while (ch=='y') { clrscr();
S.No.
CC values
Risk
printf("\n1.Insert item in que");
1.
1 to 10
Lowest
printf("\n2.Delete item from que");
2.
11 to 20
Moderate
printf("\n3.display");
3.
21 to 50
High
printf("\n4. Exit from program");
4.
> 50
Most complex
printf("\n\nenter ur choice"); scanf("%d",&cho);
Example: if (a>b) printf(“a is greater”); else printf(“b is greater”) CC = number of decision points +1 = 2+1 = 5.
5
switch(cho) {
6
case 1: if(q.rear==4 && q.front==0)
7
printf("\nit is full");
8
else { printf("\nenter item"); scanf("%d",&item); insert(item); }
9
break;
10
case 2: if(q.front==q.rear)
3
Implementing LOC and Cyclomatic Complexity metrics in Simple Queue Program in 'C' Language
#include #include # include struct que { int a[5],front,rear; }; struct que q; void insert(int); int del(); void dis();
11
printf("\nit is empty");
12
else
1
void main () {
13
break;
14
2
int cho,item,k; char ch='y';
case 3: dis(); break;
{ k=del(); printf("\ndeleted item=%d",k); }
"Pragyaan : Information Technology" Volume 7 : Issue 1, June 2009
17
Implementing Software Product Metrics in procedural Paradigm:
15
case 4: exit(0); }
16
17
Table 2. Table 2. Summary of LOC Metrics
printf("\n\npress y to cont..."); fflush(stdin); scanf("%c",&ch); }
S.no.
Functions
Line of code
1.
main()
26
2.
dis()
4
}
3.
del()
4
4.
insert()
2
// Function to display items of queue 1
The measures of the LOC metrics is done within a function only. However, this metrics can be used to measure a system also. This measurement is done by summing all LOC metric values of all functions in the system.
void dis() {
2
int i,j,k; i=q.front; j=q.rear-1;
3
for(k=i;k