Upload
ptidej-team
View
190
Download
0
Embed Size (px)
Citation preview
A New Family of Software Anti-Patterns: Linguistic Anti-Patterns
Venera Arnaoudova1, Massimiliano Di Penta2, Giuliano Antoniol1, Yann-Gaël Guéhéneuc1
1 École Polytechnique de Montréal, Canada2 University of Sannio, Benevento, Italy
1
Families ofPatterns/Anti-Patterns• Patterns, e.g., Design
• Anti-Patterns, e.g., Software Development
2
Source code lexicon
• What do we know?
• We should strive for good quality lexicon
• How is quality of the lexicon measured?
• English words, domain terms
• Abbreviations, acronyms
i.e. vocabulary of your code
3
[Takang et al., ’96], [Deissenbock and Pizka, ’05], [Lawrie et al., ’07], [Abebe et al., ’09]
What does it do?
4
• Consider method: public ??? setBreadth(Dimension target, int source){ ??? }
What does it do?
4
• Consider method: public ??? setBreadth(Dimension target, int source){ ??? }
• What is it’s return type?
What does it do?
4
• Consider method: public ??? setBreadth(Dimension target, int source){ ??? }
• What is it’s return type?
• What is it’s implementation?
What does it do?
4
• Consider method: public ??? setBreadth(Dimension target, int source){ ??? }
• What is it’s return type?
• What is it’s implementation?
What does it do?
public void setBreadth(Dimension target, int source){ target.setBreadth(source); }
Expecting:
4
• Consider method: public ??? setBreadth(Dimension target, int source){ ??? }
• What is it’s return type?
• What is it’s implementation?
What does it do?
public void setBreadth(Dimension target, int source){ target.setBreadth(source); }
Expecting:
Receiving: public Dimension setBreadth(Dimension target, int source) { if (orientation == VERTICAL) return new Dimension(source, (int)target.getHeight()); else return new Dimension((int)target.getWidth(), source); }
4
• Consider method: public ??? setBreadth(Dimension target, int source){ ??? }
• What is it’s return type?
• What is it’s implementation?
public void setBreadth(Dimension target, int source){ target.setBreadth(source); }
Expecting:
Receiving: public Dimension setBreadth(Dimension target, int source) { if (orientation == VERTICAL) return new Dimension(source, (int)target.getHeight()); else return new Dimension((int)target.getWidth(), source); }
4
Does more than it says
What does it do?
5
What does it do?Consider method:
5
What does it do?Consider method:public ??? isClassPathCorrect(wellKnownType, compUnitDecl){ ??? }
5
What does it do?Consider method:public ??? isClassPathCorrect(wellKnownType, compUnitDecl){ ??? }
• What is it’s return type?
5
What does it do?Consider method:public ??? isClassPathCorrect(wellKnownType, compUnitDecl){ ??? }
• What is it’s return type?
• What is it’s implementation?
5
What does it do?Consider method:public ??? isClassPathCorrect(wellKnownType, compUnitDecl){ ??? }
• What is it’s return type?
• What is it’s implementation?
public boolean isClassPathCorrect(..){ if(..){return true; else {return false;}}
Expecting:
5
What does it do?Consider method:public ??? isClassPathCorrect(wellKnownType, compUnitDecl){ ??? }
• What is it’s return type?
• What is it’s implementation?
public boolean isClassPathCorrect(..){ if(..){return true; else {return false;}}
Expecting:
Receiving: public void isClassPathCorrect(wellKnownType, compUnitDecl) { referenceContext = compUnitDecl; this.handle(..); }
5
Consider method:public ??? isClassPathCorrect(wellKnownType, compUnitDecl){ ??? }
• What is it’s return type?
• What is it’s implementation?
public boolean isClassPathCorrect(..){ if(..){return true; else {return false;}}
Expecting:
Receiving: public void isClassPathCorrect(wellKnownType, compUnitDecl) { referenceContext = compUnitDecl; this.handle(..); }
5
Says more than it does
What does it contain?
6
What does it contain?
• Consider attribute: private static ??? stats
6
What does it contain?
• Consider attribute: private static ??? stats
• What is it’s declared type?
6
What does it contain?
• Consider attribute: private static ??? stats
• What is it’s declared type?
• What is it’s purpose?
6
What does it contain?
• Consider attribute: private static ??? stats
• What is it’s declared type?
• What is it’s purpose?
private static int[] stats // some statistics..Expecting:
6
What does it contain?
• Consider attribute: private static ??? stats
• What is it’s declared type?
• What is it’s purpose?
private static int[] stats // some statistics..Expecting:
Receiving: private static boolean stats = true;
6
• Consider attribute: private static ??? stats
• What is it’s declared type?
• What is it’s purpose?
private static int[] stats // some statistics..Expecting:
Receiving: private static boolean stats = true;
6
Says more than it contains
Linguistic Anti-Patterns
• LAs: Recurring poor practices in the naming, documentation and choice of identifiers in the implementation.
• Different families
• One such family is related to inconsistencies:
7
• Inconsistency between a program entity’s
• documentation (i.e., comments)
• name
• behaviour (type, implementation)
8
Inconsistency LAs
Inconsistency LAs
Does more than it says
Says more than it does
Does the opposite than it says
Contains more than it says
Says more than it contains
Contains the opposite than it says
Behaviour
State
9
Dimension setBreadth(..)
void isClassPathCorrect(..)
boolean _stats
Others trust what you say!
Inconsistency LAs
Does more than it says
Says more than it does
Does the opposite than it says
Contains more than it says
Says more than it contains
Contains the opposite than it says
Behaviour
State
9
Dimension setBreadth(..)
void isClassPathCorrect(..)
ControlEnableState disable(..)
boolean _stats
Others trust what you say!
Inconsistency LAs
Does more than it says
Says more than it does
Does the opposite than it says
Contains more than it says
Says more than it contains
Contains the opposite than it says
Behaviour
State
9
Dimension setBreadth(..)
void isClassPathCorrect(..)
ControlEnableState disable(..)
int[] isReached
boolean _stats
Others trust what you say!
Inconsistency LAs
Does more than it says
Says more than it does
Does the opposite than it says
Contains more than it says
Says more than it contains
Contains the opposite than it says
Behaviour
State
9
Dimension setBreadth(..)
void isClassPathCorrect(..)
ControlEnableState disable(..)
int[] isReached
boolean _stats
//.. default exclude pattern..INCLUDE_NAME_DEFAULT
Others trust what you say!
Does more than it says
Says more than it does
Does the opposite
Behaviour
“Get” - more than an accessor
“Is” returns more than a Boolean
“Set” method returns
Expecting but not getting a single instance
Inconsistency LAs
10
Others trust what you say!
Does more than it says
Says more than it does
Does the opposite
Validation method does not confirm
“Get” method does not return
Not implemented condition
Not answered question
Transform method does not return
Expecting but not getting a collection
Behaviour
Inconsistency LAs
11
Others trust what you say!
Does more than it says
Says more than it does
Does the oppositeMethod signature and comment are opposite
Method name and return type are opposite
Behaviour
Inconsistency LAs
12
Others trust what you say!
Contains more than it says
Says more than it contains
Name suggests Boolean but type does not
Says one but contains many
Says many but contains one
Attribute signature and comment are opposite
Attribute name and type are opposite
Inconsistency LAs
State
13
Others trust what you say!
Contains the opposite
Study
• Prototype detector: LAPD
• RQ: To what extent LAs exist?
• Context: System Version Methods Attributes
ArgoUML0.10.1 5 K 3 K
ArgoUML0.34 11 K 6 K
Cocoon 2.2.0 4 K 3 KEclipse 1.0 36 K 22 K
14
Inconsistency LAs
Does more than it says
Do they exist?
Says more than it does
Does the opposite than it says
Contains more than it says
Says more than it contains
Contains the opposite than it says
Behaviour
State
Detectedwrt the
population
194 0.35%
1016 1.82%
288 0.52%
Detectedwrt the
population
438 1.3%
302 0.89%
24 0.07%
15
Inconsistency LAs
Does more than it says
Says more than it does
Does the opposite than it says
Contains more than it says
Says more than it contains
Contains the opposite than it says
Behaviour
State
Precision
88%
85%
12%
Precision
57%
75%
13%
16
Confidence: 95% ±10%
To summarize
• Defined Inconsistency LAs
• Prototype detection tool - LAPD
• 72% precision
• Inconsistency LAs represent 5% of the studied systems
17
Why do we care?
• What can go wrong with LAs:
• Useless time and effort spent to understand source code
• Wrong assumptions
• Being aware they exist is the first step...
18
The next step
• Opinion of developers
• Study the impact
• Solutions
19
Inconsistency LAs
Does more than it says
Says more than it does
Does the opposite than it says
Contains more than it says
Says more than it contains
Contains the opposite than it says
Behaviour
State
20
void getMethodBodies(..)
int isValid()
ControlEnableState disable(..)
int[] isReached
boolean _stats
//.. default exclude pattern..INCLUDE_NAME_DEFAULT
Inconsistency LAs
Does more than it says
Says more than it does
Does the opposite than it says
Contains more than it says
Says more than it contains
Contains the opposite than it says
Behaviour
State
20
void getMethodBodies(..)
int isValid()
ControlEnableState disable(..)
int[] isReached
boolean _stats
//.. default exclude pattern..INCLUDE_NAME_DEFAULT
What do you think?