Measuring Structu ral Code Quality Using Metrics · Without proper code metrics, only a complete...

8
See discussions, stats, and author profiles for this publication at: https://www.researchgate.net/publication/278786599 Measuring Structural Code Quality Using Metrics Article · June 2015 CITATIONS 0 READS 221 4 authors, including: Some of the authors of this publication are also working on these related projects: Software Cost Estimation (GP) View project 3DGAEVA for S/W project View project Koustubh Kulkarni 2 PUBLICATIONS 0 CITATIONS SEE PROFILE Yogesh Jadhav Sinhgad Technical Education Society 2 PUBLICATIONS 0 CITATIONS SEE PROFILE Dinesh Bhagwan Hanchate Vidya Pratishthan’s, College of Engineering, Baramati 104 PUBLICATIONS 80 CITATIONS SEE PROFILE All content following this page was uploaded by Dinesh Bhagwan Hanchate on 21 June 2015. The user has requested enhancement of the downloaded file.

Transcript of Measuring Structu ral Code Quality Using Metrics · Without proper code metrics, only a complete...

Page 1: Measuring Structu ral Code Quality Using Metrics · Without proper code metrics, only a complete picture of what is being produced could not be obtained. b. Without metrics automation

See discussions, stats, and author profiles for this publication at: https://www.researchgate.net/publication/278786599

Measuring Structural Code Quality Using Metrics

Article · June 2015

CITATIONS

0READS

221

4 authors, including:

Some of the authors of this publication are also working on these related projects:

Software Cost Estimation (GP) View project

3DGAEVA for S/W project View project

Koustubh Kulkarni

2 PUBLICATIONS   0 CITATIONS   

SEE PROFILE

Yogesh Jadhav

Sinhgad Technical Education Society

2 PUBLICATIONS   0 CITATIONS   

SEE PROFILE

Dinesh Bhagwan Hanchate

Vidya Pratishthan’s, College of Engineering, Baramati

104 PUBLICATIONS   80 CITATIONS   

SEE PROFILE

All content following this page was uploaded by Dinesh Bhagwan Hanchate on 21 June 2015.

The user has requested enhancement of the downloaded file.

Page 2: Measuring Structu ral Code Quality Using Metrics · Without proper code metrics, only a complete picture of what is being produced could not be obtained. b. Without metrics automation

Inventi Rapid: Soft Engineering Vol. 2015, Issue 3 2015 ese 16213 © Inventi Journals (P) Ltd

Published on Web 16/06/2015, www.inventi.in

RESEARCH ARTICLE

INTRODUCTION Software Engineering Software Engineering is an “Engineering discipline which is related with various aspects of software production from the very early stages of system specification through to maintain the system after it has gone for deployment.” Software Engineering methods provide the techniques for building software. Methods cover a broad set of tasks that include requirements gathering, analysis, system design, program construction, testing and support. Software program design tools offer programmed or maybe semi-automated assistance with the process and also the techniques. Software Development Process Software development can also be defined as application development, designing software, software application development, enterprise application development, or platform development is the development of a software product. It does not take expression consisting of everything will be engaged between your creation on the preferred software program by way of a final manifestation on the software program, essentially in a thought out in addition to structured procedure. For that reason, software program growth might include exploration, new growth, prototyping, adjustment, recycle, re-engineering, upkeep, or perhaps every other pursuits of which result in software program goods.

There are various strategies to software program growth, similar to the various views regarding political parties towards regulating any country. Many take a additional structured, engineering-based method of creating small business alternatives, in contrast to other folks normally takes an even more incremental strategy, where software program grows the way it will be produced piece-by-piece. Software Quality Metrics

1Department of Computer Engineering, Vidya Pratishthan’s College of Engineering, Baramati-413133, Pune, Maharashtra, India. E-mail: [email protected] *Corresponding author

Software Metric is a measure of some property of a

piece of software or its specifications. Due to the fact quantitative measurements are very important in all of the sciences; you will find there's ongoing hard work by personal computer scientific discipline providers and theoreticians to bring related ways of software development. The actual target is having goal, reproducible and quantifiable proportions, which could possess quite a few valuable purposes in schedule and budget planning, cost estimation, quality assurance testing, software debugging, software performance optimization and optimum staff process responsibilities.

Software functional quality reflects how well it conforms to or adheres to a given design, based on functional requirements or formal specifications. That attribute can also be depicted as suitable for purpose of a part of software or this attribute can be used to compare the products for their evaluation.

Software structural quality refers to how it meets with non-functional requirements that confirm the delivery of the functional requirements like maintainability and robustness, the degree to which the software was developed correctly.

Structural quality is assessed through the analysis of the software internal structure, its source code, in effect how its architecture binds to sound principles of software architecture. In contrast with this approach, Software testing is used for the measurement of the functional quality. Software quality measurement measures to what extent a software or system rates along each of these dimensions. A combined measure of the software quality can be computed through a quantitative or a qualitative scoring scheme or a combination of both and then a weighting system potentially reflecting the priorities. Structural code quality indicates quality of the internal structure of code which directly or indirectly affects the non functional requirements of the code. 1. Metrics Approach A metrics strategy delivers relieve on the management regarding outsourced or even sub-contracted improvement

Measuring Structural Code Quality Using Metrics

Sandesh Ganjare1*, Koustubh Kulkarni1, Dinesh B Hanchate1, Yogesh Jadhav1

Abstract: Object-oriented technology has widely accepted as the preferred way for large as well as small-scale system design. By using this advanced technology we can develop software product of lower maintenance cost and higher quality. It is clear that the available traditional software metrics are insufficient for case of object-oriented software. As a result of that, a set of new object oriented software metrics came into existence. The software test metrics which are measure of quality of the code, are very important elements of quality driven testing. They help in assuring that whether the software is appropriate or not. Result shows, the best metrics suite which covers almost all the software quality assurance features is CK metrics. Measurement of structural quality of code is necessity for ensuring overall quality of the code. Cost of maintaining and developing software is highly affected by quality and complexity of the software. In this research paper we look into several object oriented metrics as well as general code quality metrics proposed by various well known researchers. These object oriented metrics and general code quality metrics are then applied to several java programs to analyze the structural code quality of software product. Software reliability, readability, maintainability, reusability can be calculated based on the values of such metrics. These results are used for improving overall quality of the code and helping in reduction of maintenance cost.

1

Page 3: Measuring Structu ral Code Quality Using Metrics · Without proper code metrics, only a complete picture of what is being produced could not be obtained. b. Without metrics automation

Inventi Rapid: Soft Engineering Vol. 2015, Issue 3 2015 ese 16213 © Inventi Journals (P) Ltd

Published on Web 16/06/2015, www.inventi.in

RESEARCH ARTICLE

and repair has become effectively put in place through numerous companies. The complete purpose of this kind of document would be to offer solutions a number of basic inquiries in relation to your management regarding sub-contracted or even outsourced improvement and repair: a. What could be the correct metrics strategy intended for

taking care of sub-contractors? b. What can be the products your code that has been

manufactured by your sub-contractor? c. How effectively examined has been your code ahead of

supply with the sub-contractor? d. How include the on-going repair expenses linked to

your code top quality? e. What could be the position regarding automated

instruments? f. What could be the position regarding visualization?

2. Benefits of Software Metrics The knowledge on how to use certain metrics to manage the process of using sub-contractors on a project is obtained using software metrics. Specifically defining the different types of sub-contractors, it is understood how to approach the three very differing management scenarios. In addition, the use of code metrics provides a clearer insight into what the customer might really be paying for when the code is in, or moves downstream in the product life-cycle to the maintenance phase.

The benefits of using Software Metrics are: a. Without proper code metrics, only a complete picture of

what is being produced could not be obtained. b. Without metrics automation using a tool such as

McCabe IQ, user will face a complex process in focusing on the potentially problematic areas of the code base.

c. Without metrics based code visualization using a tool such a McCabe IQ, user will face a complex process in identifying and reviewing the code in the problematic areas of the code base.

d. Without a metrics-reporting tool such as McCabe IQ, user will face a complex task in managing the information that any analysis of the code base will provide.

e. Without the use of industry-accepted metrics and their associated thresholds for code, the user will face an uphill task in setting the expectations of own management chain.

Applications of the Domain Software quality objectives cover several of advanced techniques and measurements, including enforcing coding rules, gathering code metrics and proving the seizure of run-time errors. The guide also takes into account the stage of the code in the software life cycle, origin of the code and the safety aspects of the application. 1. Early verification concentrates on evaluating

intermediate software builds and this includes removing of defects at coding time. This represents a rising trend because performing verification very early in the process can help in two ways: Reduce development time, Increases overall quality.

2. Post-production verification focuses on finding defect root causes or evaluating final build quality after the product is completely developed. This is the most commonly used approach to automotive system verification. Shifting to early verification from post-production

quality assurance can require major tool and process changes. To enable constant incremental acceptance of these changes, suppliers and automotive OEMs developed a practical guide, the Software Quality Objectives document. Problem Statement Formal specifications have a variety of applications, including testing, maintenance, optimization, refectory, documentation and program repair. Software Maintenance in Software Engineering is the modification of a Software product after delivery to correct the faults and to improve performance or other attributes. Without knowing the correct notion of the program behavior it is difficult to correct the code. Nonetheless, this kind of specifications are usually hard intended for software engineers to construct as well as examine by hand, as well as automatic specification miners that will discover two-state temporary attributes possess prohibitively high false positive rates. [1] Objective of the Paper The main objective of the paper was to find the Structural quality of the software using software metrics. The quality of the code was evaluated by extracting extra information from the software engineering process. Various software metrics were used to find the quality metrics of the specific software. Software reliability, readability, maintainability, reusability can be calculated based on the values of such metrics. These results were used for improving overall quality of the code and helping in reduction of maintenance cost. QUALITY METRICS General Quality Metrics 1. Code Churn The idea make use of version control repositories to file some time involving the present revision and the past revision for every line of program code with wall clock hours. 2. Author Rank The rank of author means the actual portion of all adjustments for the repository ever before committed by means of that author. The idea files the actual rank with the past author to touch just about every line of program code. 3. Code Clones The idea show the actual measure of program code cloning for a granted program code fragment since the product connected with the size of the actual program code section in addition to the amount of occasions it's been cloned. The idea utilize open-source PMD toolkit’s clone detector to track probable copy-paste repetition.

2

Page 4: Measuring Structu ral Code Quality Using Metrics · Without proper code metrics, only a complete picture of what is being produced could not be obtained. b. Without metrics automation

Inventi Rapid: Soft Engineering Vol. 2015, Issue 3 2015 ese 16213 © Inventi Journals (P) Ltd

Published on Web 16/06/2015, www.inventi.in

RESEARCH ARTICLE

4. Code Readability This metric utilizes textual source code features-such seeing that length of variable names, number of characters, number of comments-to predict just how people would certainly determine the actual code's readability. Readability is identified over a scale through 0 to 1, comprehensive, together with 1 describing code that is highly readable. More readable code is less likely to contain errors as it creates no confusion in developer’s mind. Metrics Suite for OO Design CK metrics: The important component of process improvement is the ability to measure the process. [3] Chidamber and Kemerer proposed a suite of theoretically grounded metrics to approximate the complexity of an object-oriented design. The following five metrics apply to a particular class (i.e., a set of methods and instance variables. [5] 1. Weighted Methods per Class (WMC) It is the total Number of methods in a class, weighted by a user-specified complexity metric. It is calculated by the formula WMC = ∑n

i=1 Ci

2. Depth of Inheritance Tree (DIT) The Maximal length from the class to the root of the type inheritance tree is the Depth of Inheritance. 3. Number of Children (NOC) It is the total number of classes that directly extend the specified class. 4. Coupling between Objects (CBO) It denotes the Number of other objects to which the class is coupled. Class A is coupled to Class B if one of them calls methods or references an instance variable defined in the other. 5. Response for a Class (RFC) Size of the response set, defined as the union of all methods defined by the class and all methods called by all methods in the class. RELATED WORK Prediction of Reliability The measure of reliability guarantees whether software under development has been implemented accurately.

Figure 1: Block diagram of the system

Table 1: Result Values for Various Metrics

Properties Projects

P1 P2 P3 P4 P5 P6 P7 P8 P8 P10 Lines of code 344 545 560 470 877 800 754 1200 483 960

Number of comments

23 100 250 350 400 200 144 400 45 554

McCabe’s Complexity

3 2 8 7 4 12 3 4 2 8

WMC 41 80 19 12 28 26 12 28 45 43 RFC 15 14 16 15 32 20 15 36 67 32 DIT 3 3 2 2 5 2 2 5 6 6

LOCM 1 1 2 2 3 2 2 3 4 3 CBO 3 4 4 2 5 1 2 5 4 6 NOC 14 9 3 3 2 2 1 2 12 9

Readability 0.066 0.183 0.466 0.744 0.456 0.4 0.19 0.33 0.093 0.577 Reliability 0.0833 0.0588 0.3109 0.4276 0.1675 0.2572 0.2 0.1675 0.0416 0.0555

Maintainability 0.0.666 0.0713 0.0625 0.0666 0.0312 0.05 0.0666 0.0277 0.0149 0.0312 Regression 8.03 -20.67 19.83 22.88 8.23 9.44 21.95 6.78 -12.86 1.82 Complexity 3 2 8 7 4 12 3 4 2 8

3

Page 5: Measuring Structu ral Code Quality Using Metrics · Without proper code metrics, only a complete picture of what is being produced could not be obtained. b. Without metrics automation

Inventi Rapid: Soft Engineering Vol. 2015, Issue 3 2015 ese 16213 © Inventi Journals (P) Ltd

Published on Web 16/06/2015, www.inventi.in

RESEARCH ARTICLE

Unlike other engineering and science disciplines, absolute measurements like mass, velocity are uncommon in software engineering. Metrics were used to evaluate the process and the product (Software) in its various stages against various standards and norms. [2]

Threshold is a point beyond which there is a change in the manner a program executes. Based on these values of the threshold, threshold for software reliability can be estimated correctly. This will help the designers and developers to check the product against the threshold of reliability, if it doesn’t fall within the range, then the decision for redesign has to be made in order to meet the specifications.

The IEEE defines software reliability as “The ability of a system or component to perform its required functions under stated conditions for a specified period of time”. Software reliability actually is the probability of failure free software operation which directly or indirectly affects the system reliability and it is very different from hardware reliability in that it states the design perfection rather than manufacturing perfection. Obtaining reliability estimates early in the development process can help determine if the software system is on track to meet its reliability goals and therefore increase management effectiveness and efficiency. [2]

Calculating Threshold of Reliability

RT(Max)=k*(1/(wt(WMC)+wt(DIT)+wt(RFC)+wt(LOCM)+wt(CBO)) + (log(U-Lt(NOC)))2

RT(Min)=k*(1/(wt(WMC)+wt(DIT)+wt(RFC)+wt(LOCM)+wt(CBO)) + (log(L-Lt(NOC)))2

Accordingly Let us assume k = unity = 1

RT(Max) =1*(1/(1+1+1+1+1)) + (log(3))2 = 0 .4276

RT(Min) = 1*(1/(2+2+2+2+2)) + (log(1))2 = 0.1000

Therefore we state the Threshold for Reliability of software based on the relationship of Reliability and CK Metrics lies between 0.6777 and 0.10000. [2]

0.1000 < RT < 0.4276 Relation between CK Metrics and Maintainability The particular RFC is how many each of the methods that will likely always be executed (directly or perhaps indirectly) in response to a communication between objects of the class or perhaps simply by just about any

Figure 2: Values of regression across various java projects

Figure 3: Values of readability across various java projects

4

Page 6: Measuring Structu ral Code Quality Using Metrics · Without proper code metrics, only a complete picture of what is being produced could not be obtained. b. Without metrics automation

Inventi Rapid: Soft Engineering Vol. 2015, Issue 3 2015 ese 16213 © Inventi Journals (P) Ltd

Published on Web 16/06/2015, www.inventi.in

RESEARCH ARTICLE

process inside class. This includes most methods obtainable inside of class hierarchy.

According to CK metrics, a class with large RFC indicates the class is more complex and as we know complexity is inversely proportional to maintainability. It suggests that larger RFC indicates that class is harder to maintain. RFC increases complexity and complexity decreases maintainability. Reusability and CK Metrics Combination of two or more metrics or we can say group of metrics make impact on reusability of software code. The potential for reuse of inherited methods is greater if Deeper a particular class is in the hierarchy. It proves that reusability of your class increases using raise inside DIT of particular class. NOC having moderate value indicates scope for reuse. NOC definitely has positive effect or we can say positive impact on reusability of a class, Up to particular threshold value.

As a result the reusability of a particular class increases with the increase in combination of NOC and DIT of a particular class. So DIT + NOC have positive impact on reusability of a class. Large amount of coupling indicates flaw in class encapsulation and may subdue reuse. High LCOM increases complexity, thereby increasing chances of

errors during the development process. It indicates that coupling negatively affects reusability of a class. The class should split into two or more number of smaller classes. It implies that cohesion has negative impact on reusability of a class. [3]

Therefore LCOM+CBO have negative effect on reusability of a class. The large no. of methods in a class, the greater the possible impact on derived Classes with huge no. of methods are likely to be more product specific, limiting the possibility of reuse. So High WMC negatively affects reusability of a class. The complexity of the class increases as larger the no. of methods that can be called from a class through message. So RFC negatively affects reusability of a class. Which means reusability of a particular class lowers with the increase in combination of RFC and WMC of that class Therefore RFC+WMC have negative effect on reusability of class. [3-13] RESULTS AND DISCUSSION Result values for various metrics are shown in Table 1.

These metrics were calculated and tested on several java programs and following points are observed: 1. The WMC metric act as a predictor of how much efforts

and time is required to maintain and develop the whole class. Potential impact on children increases with larger

Figure 4: Values for positive impact and negative impact of metrics on reusability

Figure 5: Comparison of maintainability vs. RFC

5

Page 7: Measuring Structu ral Code Quality Using Metrics · Without proper code metrics, only a complete picture of what is being produced could not be obtained. b. Without metrics automation

Inventi Rapid: Soft Engineering Vol. 2015, Issue 3 2015 ese 16213 © Inventi Journals (P) Ltd

Published on Web 16/06/2015, www.inventi.in

RESEARCH ARTICLE

the no of methods in a class. Derived classes inherit all of the methods defined in the base class. Classes with huge numbers of methods are likely to be more Product specific, limiting the possibility of reuse. It was observed that the density of bugs and defects increased with an increase in the average WMC and decreases reusability and overall quality.

2. The deeper class in the hierarchy inherits more no of a method that makes it more complex. Deep trees as such indicate greater design complexity. On a positive side, deep trees promote reuse because of method inheritance. As per our observations, java programs have intermediate value for DIT metric.

3. Since RFC specifically includes methods invoked from outside the class, it is also a measure of the communication between the particular class and other classes. More faults are observed where RFC is high. Classes with a high RFC are harder to understand and more complex and therefore harder to maintain. Debugging and Testing of such classes is complicated. A study of various java programs indicate that an increase in RFC decreases overall quality and increases the density of bugs.

4. Since inheritance is a form of reuse, high NOC indicates high reuse. A large number of children (high NOC) may also mean not suitable abstraction of the base class. If a class has too many children, it may indicate misuse of sub-classing. A class with many children may also require more intensive testing. High NOC has been found to indicate fewer faults. This may be due to high reuse, which is desired. In java the value of this metric depends on program to program. All classes do not have the same number of sub-classes. However, it is observed that for better results, classes higher up in the hierarchy should have more sub-classes then those lower down.

Total Impact on Reusability Here it was observed that, some group of metrics have positive impact on the calculation of the reusability and some have negative impact. As we observed in result DIT+NOC have positive impact and CBO+LCOM and WMC+RFC have negative impact on it. We can calculate

total impact of metrics on reusability by adding positive and negative impact.

Total impact = Positive impact + Negative impact

Relative Performance Finally, we calculated the relative performance by multiplying all the values of performance measure and dividing total no. of measures. CONCLUSION Software developers can benefit from an early estimate regarding the quality of their product as field quality information is often available late in the software lifecycle to affordably guide corrective actions. Identifying early indicators of field quality is very important. Moreover it is very necessary and effectively reduces the cost of the software and also the maintenance time. The code quality was measured by extracting extra information from the various software engineering processes. The quality metrics was used for this purpose.

The software was tested with unstructured code which results in low value of accuracy. It indicated that the input given was poor quality software. Thus the software was checked for negative results. Software reliability, readability, maintainability, reusability can be calculated based on the values of such metrics. These results were used for improving overall quality of the code and helping in reduction of maintenance cost. REFERENCES 1. C Le Goues and W Weimer. Measuring code quality to improve

specification mining. IEEE Transactions on Software Engineering, 38(1):175-190, 2012.

2. Johny Antony P. Predicting Reliability of software using thresholds of CK metrics. International Journal of Engineering Research & Technology, 2(6):1136-45, 2013.

3. Brij Mohan Goel, Pradeep Kumar Bhatia. Analysis of reusability of object-oriented system using CK metrics. International Journal of Computer Applications 60(10):32-36, 2012.

4. C Le Goues and W Weimer. Specification mining with few false positives. Proc Int Conf Tools and Algorithms for the Construction and Analysis of Systems, 292-306, 2009.

Figure 7: Comparison of values of various metrics and reliability

6

Page 8: Measuring Structu ral Code Quality Using Metrics · Without proper code metrics, only a complete picture of what is being produced could not be obtained. b. Without metrics automation

Inventi Rapid: Soft Engineering Vol. 2015, Issue 3 2015 ese 16213 © Inventi Journals (P) Ltd

Published on Web 16/06/2015, www.inventi.in

RESEARCH ARTICLE

5. S R Chidamber and C F Kemerer. A Metrics Suite for Object Oriented Design. IEEE International Conference on Data Mining, 150-159, 2008.

6. G Ammons, R Bodik and J R Larus. Mining Specifications. Proc. ACMSIGPLAN-SIGACT Symp. Principles of Programming Languages, 4-16, 2002.

7. W Weimer and G C Necula. Mining Temporal Specifications for Error Detection. Proc Int Conf Tools and Algorithms for the Construction and Analysis of Systems, 461-476, 2005.

8. J Yang, D Evans, D Bhardwaj, T Bhat and M Das. Perracotta: Mining Temporal API Rules from Imperfect Traces. Proc Int Conf Software Eng, 282-291, 2006.

9. D R Engler, D Y Chen and A Chou. Bugs as Inconsistent Behavior: A General Approach to Inferring Errors in Systems Code. Proc Symp Operating System Principles, 57-72, 2001.

10. M H Tang, M H Kao and M H Chen. An Empirical Study on Object-Oriented Metrics. Proc Int Symp Software Metrics, 242-249, 1999.

11. T J McCabe. A Complexity Measure. IEEE Trans Software Eng, 2(4):308-320, 1976.

12. M Halstead. Elements of Software Science. Elsevier, USA, 1977. 13. P G Hamer and G D Frewin M H Halsteada. Software Science -

A Critical Examination. Proc. Inta Conf Software Eng, 197- 206, 1982.

Cite this article as: Sandesh Ganjare, Koustubh Kulkarni, Dinesh B Hanchate et al. Measuring Structural Code Quality Using Metrics. Inventi Rapid: Soft Engineering, 2015(3):1-7, 2015.

7

View publication statsView publication stats