Antipattern and Code Smell Preliminary Conceptualization and Classification
Francesca Arcelli Fontana, Jens Dietrich, Bartosz Walter, Aiko Yamashita SANER - Osaka, March 2016
ANTI-PATTERNS AND A
affect negatively future maintenance and evolution.
EXAMPLE OF Abstraction without decoupling Client depends on a service (supertype) and the implementation of the service (subtype) at the same time
Service locator pattern Create a service locator that contains references to the services and that encapsulates the logic that locates them.
EXAMPLE OF Long parameter list Too many parameters in a method can lead to defects (e.g., slips) and reduces readability...
Person
Person
getAddress(street, postcode, country) setAddress(street, postcode, country)
getAddress(Address) setAddress(Address)
Person
Person
getAddress(street, postcode, country) setAddress(street, postcode, country)
getAddress(Address) setAddress(Address)
Introduce Parameter Object Encapsulates the complexity of the parameter list into an object.
on s e i d u t s l pirica m he e t n o t o t s c w e e p i res rev h t m i o w r f e s v lity t i i l s b u u a l c n i n Res a t o c n i ma n are in o s l l e e v a m h s s e ll e (2012) m cod a s it h e s a d m o a ,Y cts c e f f al. (2010) e t e l g a n a u h t Z ac
The prese nce of cer tain anti-pa predomina tterns is ra nt in real w ther or ld softw are system Melton an s d Temp ero (2007 ), Dietrich
to s i s y l a n a ell m s e s is d o m c e l f b o o r y ce p pacit n a a c n l l e a t r n i e Ov t ma c i d e r p st r e o d o n i m a l (2013) r g p r e e b h ex t jø ra 2012), S a Yamashit
(
et al., (201
0)
de o c e k a es m v i t i s o p ns r e e s l t t a f a f p o i nts /ant u s l l o e m m a s e d on Larg e s a e.. c b i t n c a o i r t p c in e inspe v i t i b i h pro
o the s l a e db l u o c tion y c i t i d d e i r l va y/p r t o c t u a r not n t a s l e r n p a x o e s C ell hy m w s n e o d s rea h co so well! t i w s l mode erforming p
do I really need to check all of them?
METHODOLOGY Meta-synthesis Useful to cover work that is “refutational”, or that may present oppositional conclusions from the main body of work or understanding (Noblit and Hare 1998)
Catalogue Similar to documenting patterns, but for identifying and understanding the conditions (contextual) in which they constitute false positives
Category
Category
Category
Classification Bottom-up Conceptualization FP
FP FP
FP FP
FP FP
FP
FP
FP FP
Grouping according to emerging topics FP FP
OVERVIEW OF CATALOGUE
12 anti-patterns and • Refused Bequest code smells covered • Message Chains • God Method • God Class • Feature Envy • Dispersed Coupling • Duplicated Code • Data Clumps • Data Class • Shotgun Surgery • Circular Dependencies Between Packages • Subtype Knowledge
Definition
Description
Argumentation for existence of FP
Synonyms
Empirical studies Theory Practical experiences
Examples (code)
Concrete instances of FP
Relevant contextual factors Preliminary Catalogue of Anti-pattern and Code Smell False Positives Technical Report RA-5/2015
Poznań University of Technology
Factor Implication
EXAMPLE Definition
Data$Class:$“Dumb”$data$holders$without$complex$func:onality
Argumentation for existence of FP
Li$&$Shatnawi$(Large$FLOSS$Java$systems)$$$
–"Not"associated"significantly"with"soLware"faults"
Empirical studies
Sjøberg$(small/medium$industrial$systems)
–"Not"correlated"with"increased"maintenance"effort" Khomh$et$al$(Large$FLOSS$Java$systems
–"Not"correlated"with"change"proneness
Theory
!""Desirable"to"wrap"data"into"a"single"object"without"gran6ng"it"func6ons" !""Jus6fied"by"performance"tuning"efforts" !""DTO"(Data"Transfer"Object)"is"an"enterprise"paAern
Relevant contextual factors Contextual Factor Implication
Concrete instances of FP
Excep1on&Handling&Class
Distributed"processing/IPC/ mul6!6er"applica6on
Evolu6on"of"tasks/func6onality" degree"of"automa6on
Data"Classes"group"individual" data"items"for"improving" performance"of"data"transfer" between"applica6on"layers.
If"there"are"many"changes"needed"on"the" abstrac6ons"used"in"the"system"
Serializable&Class
Degree"of"automa6on"and"cost"of"the" individual"changes"of"the"Data"Classes"
Test&Class
Logger&Class
CLASSIFICATION
Category
Category
Category
Bottom-up Conceptualization FP
Category 1: Imposed Anti-patterns and smells
FP FP
FP FP
FP FP
FP
FP
FP FP
FP FP
Singleton and Abstract Factory
Sub-category 1.1: Anti-patterns and smells imposed by Design Patterns
(can induce Subtype Knowledge)
Design patterns can directly cause certain anti-patterns or smells
Builder (can induce Message Chain) Logger Class (detected as Data Class) Visitors (can cause circular dependency and detected as God Class)
Sub-category 1.2: Anti-patterns and smells imposed by the Programming Language used
Sub-category 1.3: Anti-pattern and smells imposed by frameworks
Certain designs are used to overcome limitations of the programming language
Serializable Class
Tradeoffs (given by frameworks) between antipatterns and other more valued qualitative attributes in a context
GUI widget toolkits could lead to God Classes
(detected as Data Class)
Exception Handling Class (detected as Data Class)
Getter/Setter Method could lead to Shotgun Surgery
Sub-category 1.4: Anti-patterns and smells imposed by optimisations Sub-category 1.5: Anti-patterns and smells imposed by porting code from a non-object-oriented programming language Sub-category 1.6: Anti-patterns and smells inherited from legacy code
CLASSIFICATION
Category
Sub-category 2.3: Inadvertent antipatterns and smells caused by analysis scope
FP FP
Category 2: Inadvertent anti-patterns and smells
Sub-category 2.2: Inadvertent antipatterns and smells caused by program representation
Category
Bottom-up Conceptualization FP
Sub-category 2.1: Inadvertent anti-patterns and smells caused by source code generators
Category
FP FP
FP FP
FP
FP
GUI builders
Generated code contains anti-patterns and smells
Program representations can impact precision (Bytecode vs. Source code)
Certain parts of the project may not reach production
Entity Modelling Class
Parsers
Constant inlining Shotgun Surgery instances)
Test Classes and Methods
FP FP
FP FP
WHAT TO TAKE HOME TODAY... Anti-patterns and code smells
‣ Current evidence on deterrent effect of AP/CS and is not too strong ‣ Lack of
for explanatory/prediction models of AP/CS underperforming
‣ Large amount of AP/CS ‣ Interpretive research (meta-synhesis) on current studies/theories are good for: ‣ Identifying refutational evidence/argumentation ‣ Understanding better the factors under which AP/CS have an effect (or not) ‣ Preliminary catalogue of False Positives ‣ Bottom-up classification
Work in progre ss!
‣ Future (on going) work: - Implementation of filters based on False Positive definitions - Considering FP can lead to more depurated prediction/explanatory models? - Guidelines for performing tradeoff analysis for AP/CS interpretation
“no metric or indicators can compete with human intuition”
ありがとうございます
THANK YOU!
[email protected]