You are on page 1of 5

Software Maintenance: Role of metrics and Smells

in object oriented softwares

Junaid Ali Reshi Satwinder Singh


Center for Computer Science and Technology Center for Computer Science and Technology
Central University of Punjab Central University of Punjab
Bathinda, India Bathinda, India
jreshi14@gmail.com satwindercse@gmail.com

Abstract—Software maintenance has been a topic of great Apart from these maintenance activities, emergency
interest to both the Industry and academics. There have been maintenance, listed as a part of corrective maintenance is
various efforts in improving the software life through various tools defined as “An unscheduled modification performed to
and techniques. This paper examines the essence of software temporarily keep a system operational pending corrective
metrics and bad smells in software maintenance. The study maintenance”. Further down the line, maintainability of a
considers various standard metrics and smells and examines the software system is defined as “The capability of the software
role they play in software maintenance. The study concludes that product to be modified. Modifications may include corrections,
the software metrics have been used for defect prediction in quite improvements or adaptation of the software to changes in
a number of researches whereas code smells are predominantly
environment, and in requirements and functional specifications”
used for refactoring and have been undermined when it comes to
defect prediction. As software maintenance is a continuous process that exists
throughout the overall lifespan of a software product, software
Keywords—code smells; defect prediction; machine learning; development organizations aim to design the software products
software metrics that are easy to maintain. There are various factors that help in
effective software maintenance by detecting the code anomalies
I. INTRODUCTION and their symptoms. More specifically, the prediction of faults
Software maintenance is the longest phase of a successful through metrics, or possible flaws in the software systems
software lifecycle. The definition of software maintenance through code smells helps in maintainability of a software. Code
as given in the IEEE Standard for Software Maintenance [1] smell, a symptom of poor design and implementation choice, has
is as follows: “The totality of activities required to provide been found to have significant effect on software
cost-effective support to a software system. Activities are maintainability. Technically, code smells do not hamper the
performed during the pre-delivery stage as well as the post- software system functionality but they tend to increase the risk
delivery stage”. This, in essence, means that any activity that of system failure in future. Likewise, software metrics, the
concerns software system after or before its release is measure of different parameters of the software code, have also
software maintenance. Further, the document defines four been found to be effective in predicting faults in a software
different types of maintenance tasks: system through the development of various defect prediction
models.
 Adaptive maintenance is defined as: “The modification
of a software product, performed after delivery, to keep Metric rules and static code analysis have been employed to
a software product usable in a changed or changing design various tools for the detection of code smells [2], [3],
environment.” [4].Some studies have been conducted to determine the side
effects of code smells on software maintainability [5], [6], [7],
 Corrective maintenance is defined as: “The reactive change-proneness [8], [9] and understandability [10]. In their
modification of a software product performed after study, Yamashita and Moonen [7] have investigated the
delivery to correct discovered problems.” relationship between certain inter-smells with some problems
during maintenance which also include the introduction of
 Perfective maintenance is defined as: “The defects to the system.
modification of a software product after delivery to
detect and correct latent faults in the software product
before they are manifested as failures.” II. LITERATURE REVIEW
Software maintainability has to be measured or quantified for
 Preventive maintenance is defined as: “The understanding it better and for making comparisons based on it.
modification of a software product after delivery to There have been various efforts on developing metrics for
detect and c orrect latent faults in the software product quantifying a software system. Various studies that have
before they become operational faults” provided with some software metrics claim their metrics to be a
good indicator of software maintainability. Researchers have
recently been focusing their studies on evaluating software method pairs whose similarity (measured through used instance
maintainability through a group of metrics. This approach seems variables) equals zero minus the number of method pairs whose
to be more feasible as it helps to correlate metrics with the similarity is not zero. This, again, does not imply the measure of
maintainability and thus gives a better understanding of the strength of lack of cohesion as the class which have the same
relation between metrics and maintainability. value (zero) for it can have different intensity of cohesion.
We will focus on the object-oriented systems only and study the Class cohesion being a good fault predictor is still a topic of
various metrics and their effects on the object-oriented systems. interest. Some studies suggest that cohesion provides indication
about fault-proneness [17] whereas some claim that it has no
A. Object-Oriented metrics: Coupling and Cohesion relation with it [11] [15]. Misic [19] suggests that coherence (his
The main motive under object oriented programming is to name for cohesion) can be measured by the usage of the class in
create a single unit of functionality, known as class, which question by external classes. In their paper, Counsell et al. [20]
contains data and the methods. Metrics as quality is used in discuss the difficulty of confining the definition of cohesion.
several studies such as done by Basili et al. [11]. One of the Li & Henry [21] conducted a study on the correlation of
pioneering work in proposing a metrics suite for object-oriented maintenance effort and object-oriented metrics. They have used
system has been done by Chidamber and Kemerer [12].The the object-oriented metrics as given by Chidamber & Kemerer
metrics suite designed by them contained the following metrics: [12]with slight modifications. They conclude the object-oriented
Weighted Methods Per Class, Depth of Inheritance Tree, metrics under study can be used as maintenance predictors. On
Number of Children, Coupling Between Object Classes, the basis of their comparison, they conclude that object-oriented
Response for a Class, and Lack of Cohesion Methods. metrics are better predictors of maintenance effort than simple
The concept of cohesion and coupling were introduced by size metrics (such as lines of code) alone [12]. Gyimothy et al.
Stevens et al. [13] who were researchers at the IBM. Their [22] used logistic regression and other machine learning
concept still holds and is an important factor in the object- techniques to study and compare the efficiency of sets of
oriented programming as some important metrics are derived Chidamber and Kemerer metrics to predict fault-prone classes
from their concept, which holds good till this day also. The term within Mozilla. They concluded CBO being the most efficient
coupling in object-oriented programming means the dependence metric and that the performance of LOC to discriminate fault-
between classes and/or objects. Chidamber and Kemerer, in their prone classes is also good. In another study, Bandi et al. [23]
study, presented a coupling metric which they name as coupling suggest maintenance performance to be dependent on design
between object classes (CBO) and they define it as follows complexity, maintenance task, and programmer ability.
“CBO for a class is a count of the number of other classes to Cartwright and Shepperd [24] conducted an empirical study on
which it is coupled” [12]. They explain that when methods of an industry based C++ system and suggested that among the
one class use the instance variables or methods of another class, metrics suite given by Chidamber and Kemerer, DIT and NOC
it leads to coupling [12]. Therefore, it can be inferred that CBO metrics [12] could be used efficiently to find classes having
is count of the number of classes that interact with the measured higher fault rates. Zimmermann et al. [25]conducted an
class. However, Chidamber & Kemerer don’t mention the empirical research on Eclipse suggesting that the faults in a code
intensity that measured class uses the methods or instance are directly proportional to the code complexity and that
variables of the other class, referred to as tightness of coupling combination of complexity metrics can predict faults efficiently.
[12]. Ma, Chang,Cleland-Huang [14], in their study, discuss El Emam et al. [16] in their study concluded that the correlation
coupling tightness in context to the object-to-object between metrics and fault-proneness disappeared when size was
programming. not taken into consideration. They thus suggest that many of the
metrics are correlated with the function of size and, therefore,
In their work, [15] state that the provision of friend class in are not useful in providing information to predict fault
C++ increases coupling as it allows a friend class to access other proneness.
class members. They further hint that Java’s package
mechanism is analogous to C++ friendship mechanism and B. Code Smells
hence it also affects coupling. Some studies such as that of [11], Webster [26] made the first attempt to explain antipatterns
[15], [16], [17] suggest that some kinds of coupling have a in object-oriented development. In his study, he focusses on the
degree of correlation with fault metrics, though all of them not conceptual, coding, and quality-assurance problems. Riel [27],
being equally significant. in order to improve design and implementation of an object-
In object-oriented paradigm, two levels of cohesion can be oriented system, defined 61 heuristics to assess a system quality
defined, functional (between methods) and class level (between manually. These heuristics define good object-oriented
classes). Functional cohesion is easy to analyze while characteristics and are somewhat similar to code smells. Fowler
quantifying the class level cohesion is slightly more difficult. [28], in one of his books defines 22 code smells. Mantyl [29] and
Grigg, while discussing [18] states that an indication that a class Wake [30] have also proposed some classifications for code
is too big can be found by answering the question “what does smells. In their study, Brown et al. [31] have described 40
this class do?” and counting the and-words thereof. But, this antipatterns, mostly in terms of lower-level code smells. These
measure does not provide us an unambiguous measure for class literatures present in-depth theoretical views on antipatterns,
level 5. In their study, Chidamber and Kemerer (Chidamber & heuristics and code smells and form the basis of many
Kemerer 1994) propose a class level cohesion metric called approaches to specify and detect code smells, both manually or
Lack of Cohesion in Methods (LCOM), as the number of through some models.
There have been a lot of studies proposing different  Shotgun Surgery: This smell is prevalent when one
approaches to identify and detect code smells and antipatterns. change requires altering of many classes. The process
These works propose different approaches ranging from manual to reduce this kind of smell will push the system
inspection based techniques [32], to metric based heuristics [33], towards another smell, the divergent change. But, with
[34].In metrics based heuristics, code smells and–or antipatterns the right balance of it, the system can work efficiently.
are identified according to defined sets of rules and already
defined threshold values of various metrics. There have been  Feature Envy: This smell indicates that a method
various studies where rules have been defined using fuzzy logic seems more interested and involved in other class(es)
and executed by means of a visualisation techniques [35] , [36]or than the one where it is located currently.The most
rule-inference engine [37].Studies like [38], [39] suggest common focus of a method like this is the data in other
approaches performing fully automatic detection and using classes. Therefore, this method can be regarded at
visualisation techniques to present the detection results. Some wrong place as it is more tightly coupled to some other
studies have suggested that using Semi-automatic approaches is class than to the one where it is actually belongs.Fowler
more productive and suitable.Using semi-automatic approaches et al. have listed various remedies to remove this kind
has been regarded as an interesting tradeoff between fully of smell [28].
automatic detection techniques which can be efficient but stray  Data Clumps:This type of smell means some data
away from the context, and manual inspections that need human items in a software often appear together in different
expertise and are comparatively slow and more subjective [40]. classes,parameter and method signatures and that
Fowler et al. identified 22 different code smells in his removing one of the group’s data items renders them
book.Those 22 code smells are listed as: meaningless.Fowler et al. suggest that a new object
creation is the remedy [28].
 Duplicate code : According to Fowler et. al. [28],
duplicate code is the number one problem in smell  Primitive Obsession: This kind of smell represents a
intensity among smells.They firther state that we situation when primitives are used for small tasks,
should try to unify the duplicate code in our instead of small classes. For example, to represent
program.They discuss duplicacy at method level and money in a program, programmers are reluctant to use
class level and suggest possible remedies to remove a separate class that could encapsulate various
duplicate code in different scenarios. functionalities like currency conversion ,and tend to
use primitives thereby generating this smell.
 Long Method: Whenever methods stretch too much in
their length, they are called as long methods.The long  Switch Statements: This type of smell is associated
methods have an inherent problem of with the wrong use of switch (or case) statements
understandability,changeability and extensibility. through duplication in the code.It should be noted that
Fowler et al. [28] strongly suggest in decomposing mere presence of a switch operator does not imply a
methods and keeping them short.They also suggest smell. The smell originates in the case when type codes
how methods can be kept short to yield the benefits of or runtime class type detection are used as switch
the Indirection. determinants instead of polymorphism.

 Large Class: According to Fowler et al., “A class  Parallel Inheritance Hierarchies: This smell has
with too many instance variables, a class with too much been regarded as a special case of shotgun surgery by
code is prime breeding ground for duplicated code, Fowler et al. .It is implied by a situation where parallel
chaos, and death” [28].They suggest different remedies class hierarchies exist and if we want to make some
for removing redundancy in different cases pertaining changes in one classes hierarchy, it necessaciates
to a class. extension of both hierarchies.

 Long Parameter List : If the paramter list is too long  Lazy Class: A class that is not useful enough or has
or changes often, it is bound to cause some problems. ceased to be useful due to refactoring, non
Fowler et al. suggest to pass a method enough so that implementaton of plans etc. comes under this
the method gets to everything it needs.They suggest smell.Such a class should be removed with appropriate
some changes to reduce the number of parameters in action.
the argument list of a method.They also caution about  Speculative Generality: This kind of smell is
the scenario when to reduce dependency deliberate generated when unnecessary code is added to the
long parameter list is used [28]. system, anticipating the future augmentations in the
 Divergent Change: This is the type of smell that is software. This leads to a code that is harder to maintain
indicative of the fact that a class is changed frequently, and understand. Fowler et al. [28] suggest some
in different ways for different reasons. This reults in the remedies for this kind of smell.
frequent change in the pattern of a class for entirely  Temporary Field: This smell is present when an
different reasons (functionalities) of databases and instance variable is making code difficult to
financial instruments and thus may cause problems in comprehend, as it is used in certain circumstances only.
aa software.
Beck suggests creating method object for dealing with code smells. Therefore, more studies are needed to study the
this type of scenario [28]. effect of combination of software metrics and code smells for
defect prediction through the application of any advanced
 Message Chains: This smell arises when a class asks
an object for another object, which then asks another technique such as machine learning algorithms, and the
and so on.This results in the series of calls which occur software under study being an industrial one.
back to back. This means that the first class will be
coupled to the structure of navigation and any change
IV. REFERENCES
in the intermediate relationships necessiate the first
class to have change. To reduce this coupling,Fowler et
al. suggest to do this work with methods or use objects [1] "IEEE Standard for Software Maintenance," IEEE, 2006.
as middlemen through hiding them [28]. [2] M. Boussaa, W. Kessentini, W. Kessentini, S. Bechikh and S. B. Chikha,
"Competitive co-evolutionary code smells detection," International
 Middle Man: This smell prevails when a class Symposium on Search Based Software Engineering, pp. 50-65, 2013.
delegates most of its tasks to other classes. Although, [3] R. Marinescu, "Detection strategies: Metrics-based rules for detecting
delegation through classes is a common practice in design flaws," in Proceedings. 20th IEEE International Conference on
object-oriented programming,if there is too much Software Maintenance, 2004.
delegation it can seriously affect the program. [4] N. Moha, Y. G. Gueheneuc, L. Duchien and A. F. Le Meur, "Decor: A
method for the specification and detection of code and design smells,"
 Inappropriate Intimacy: This smell emanates when IEEE Transactions on Software Engineering, vol. 36, no. 1, pp. 20-36,
two classes are too tightly coupled with each other. 2010.
Fowler et al. suggest that this intimacy may lead to [5] D. Sjoberg, A. Yamashita, B. C. D. Anda, A. Mockus and T. Dybå,
some unacceptable behavior in the system. They "Quantifying the effect of code smells on maintenance effort," IEEE
Transactions on Software Engineering, vol. 39, no. 8, pp. 1144-1156,
suggest the techniques to break them up [28].
2013.
 Alternative Classes with Different Interfaces: This [6] A. Yamashita and L. Moonen, "Do code smells reflect important
smell is indicative of a case when a class operates with maintainability aspects?," in 28th IEEE International Conference on
different classes, but the interface to these alternative Software Maintenance (ICSM), 2012.
classes being different. [7] A. Yamashita and L. Moonen, "Exploring the impact of inter-smell
relations on software maintainability: An empirical study.," in
 Incomplete Library Class: This smell is indicative of Proceedings of the 2013 International Conference on Software
the situation when the software utilizes a library that is Engineering, 2013.
in bad form or incomplete. This implies that developers [8] F. Khomh, M. D. Penta, Y. -G. Gueheneuc and G. Antoniol, "An
need to extend the functionality of the library for exploratory study of the impact of antipatterns on class change-and fault-
proneness," Empirical Software Engineering, vol. 17, no. 3, pp. 243-275,
making software run properly. 2012.
 Data Class: This smell is characterised by a class [9] F. Khomh, M. D. Penta and Y. -G. Gueheneuc, "An exploratory study of
which contains data, but almost no methods. This is a the impact of code smells on software change-proneness," in 16th
Working Conference on Reverse Engineering,WCRE’09, 2009.
bad practice as classes, in practice, must contain both
data and logic. [10] M. Abbes, F. Khomh, Y. G. Gueheneuc and G. Antoniol, "An empirical
study of the impact of two antipatterns, Blob and Spaghetti Code, on
 Refused Bequest: This type of smell emanates when a program comprehension.," in 15th European Conference on Software
Maintenance and Reengineering (CSMR) , Oldenburg, 2011.
child class does not fully support all the data or method
it inherits from a parent. When a class refuses to [11] V. R. Basili, L. C. Briand and W. L. Melo, "A validation of object-
oriented design metrics as quality indicators," IEEE Transactions on
implement an interface, this makes the worse case of software engineering, vol. 22, no. 10, pp. 751-761, 1996.
smell.
[12] S. R. Chidamber and C. F. Kemerer, "A metrics suite for object oriented
 Comments: Every comment is not necessarily a bad design," IEEE Transactions on software engineering, vol. 20, no. 6, pp.
476-493, 1994.
smell.Comments, when superflous can cause some
trouble as they can be misused to adjust poorly [13] W. P. Stevens, G. J. Myers and L. L. Constantine, "Structured design,"
IBM Systems Journal, vol. 13, no. 2, pp. 115-139, 1974.
structured code and act as deodrant.
[14] C. S. Ma , C. K. Chang and J. Cleland-Huang, "Measuring the intensity
of object coupling in c++ programs," in 25th Annual International
III. CONCLUSION Computer Software and Applications Conference, COMPSAC 2001,
2001.
There has been a lot of research on the topic of software metrics.
[15] L. C. Briand, C. Bunse , J. W. Daly and C. Differding , "An experimental
The research mostly focuses on the software metrics to be used comparison of the maintainability of object-oriented and structured
for different purposes. Apart from this, software metrics as design documents," Empirical Software Engineering, vol. 2, no. 3, pp.
defect predictors have also been widely discussed in the 291-312, 1997.
literature. The software code smells have not been rigidly [16] K. El Emam, S. Benlarbi, N. Goel and S. Rai, "The confounding effect
defined and as such their definition varies from a researcher to of class size on the validity of object-oriented metrics," IEEE
Transactions on Software Engineering, vol. 27, no. 7, pp. 630-650, 2001.
another. There have been very less studies on the role of
[17] Y. Ping, T. Systa and H. Muller, "Predicting fault-proneness using OO
software smells as defect predictors in object oriented systems metrics. An industrial case study," in Sixth European Conference on
and no model has been developed for defect prediction through Software Maintenance and Reengineering, 2002.
[18] J. Grigg, Re: [refactoring] Size of Java Classes? Refactoring mailing list, [31] W. J. Brown, R. C. Malveau, H. W. McCormick and T. J. Mowbray,
2002. AntiPatterns: Refactoring Software, Architectures, and Projects in Crisis,
[19] V. B. Misic, "Cohesion is structural, coherence is functional: Different First ed., Wiley, 1998.
views, different measures," in Seventh International Software Metrics [32] G. Travassos, F. Shull, M. Fredericks and V. R. Basili, "Detecting defects
Symposium, METRICS 2001, 2001. in object-oriented designs: using reading techniques to increase software
[20] S. Counsell, E. Mendes and S. Swift, "Comprehension of object-oriented quality," in 14th Conference on Object-Oriented Programming, Systems,
software cohesion: the empirical quagmire," in 10th International Languages, and Applications, 1999.
Workshop on Program Comprehension, 2002, 2002. [33] R. Marinescu, "Detection strategies: Metrics-based rules for detecting
[21] W. Li and S. Henry, "Maintenance metrics for the object oriented design flaws," in 20th IEEE International Conference on Software
paradigm," in First International Software Metrics Symposium, 1993. Maintenance, 2004.
[22] T. Gyimothy, R. Ferenc and I. Siket, "Empirical validation of object- [34] M. J. Murno, "Product metrics for automatic identification of" bad smell"
oriented metrics on open source software for fault prediction," IEEE design problems in java source-code.," in 11th IEEE International
Transactions on Software engineering, vol. 31, no. 10, pp. 897-910, Software Metrics Symposium (METRICS'05), 2005.
2005. [35] K. Dhambri, H. Sahraoui and P. Poulin, "Visual detection of design
[23] R. K. Bandi, V. K. Vaishnavi and D. E. Turk, "Predicting maintenance anomalies," in 12th European Conference on Software Maintenance and
performance using object-oriented design complexity metrics," IEEE Reengineering (CSMR 2008), 2008.
Transactions on software engineering, vol. 29, no. 1, pp. 77-87, 2003. [36] S. Frank, F. Steinbruckner and C. Lewerentz, "Metrics based
[24] M. Catwright and M. Shepperd, "An empirical investigation of an object- refactoring," in Fifth European Conference on Software Maintenance
oriented software system," IEEE Transactions on software engineering, and Reengineering, 2001.
vol. 26, no. 8, pp. 786-796, 2000. [37] E. H. Alikacem and H. Sahraoui, "Generic metric extraction framework,"
[25] T. Zimmermann, R. Premraj and A. Zeller, "Predicting defects for in 16th International Workshop on Software Measurement and Metrik
eclipse," in International Workshop on Predictor Models in Software Kongress (IWSM/MetriKon), 2006.
Engineering PROMISE'07: ICSE Workshops 2007, 2007. [38] M. Lanza and M. Radu, Object-Oriented Metrics in Practice, Springer,
[26] B. F. Webster, Pitfalls of object oriented development, M & T Books, 2006.
1995. [39] V. Emden, Eva and L. Moonen, "Java quality assurance by detecting
[27] A. J. Riel, Object-Oriented Design Heuristics, Addison Wesley, 1996. code smells," in Ninth Working Conference on Reverse Engineering,
2002.
[28] M. Fowler, K. Beck, J. Brant, W. Opdyke and D. Roberts, in Refactoring:
Improving the Design of Existing Code, Addison Wesley, 2002, pp. 63- [40] G. Langelier, H. Sahraoui and P. Poulin, "Visualization-based analysis
72. of quality for large-scale software systems," in 20th IEEE/ACM
international Conference on Automated software engineering, 2005.
[29] M. Mäntylä, "Bad smells in software-a taxonomy and an empirical
study," Helsinki University of Technology, 2003. [41] T. Menzies, J. Greenwald and A. Frank, "Data mining static code
attributes to learn defect predictors," IEEE Transactions on Software
[30] W. C. Wake, Refactoring Workbook, Addison-Wesley Professional, Engineering, vol. 33, no. 1, pp. 2-13, 2007.
2003.

You might also like