The document presents a new category of software anti-patterns called linguistic anti-patterns (LAs). LAs refer to poor naming, documentation, and identifier choices that introduce inconsistencies. Six specific inconsistency LAs are defined related to a program element's documentation, name, and behavior being inconsistent. An initial study of four systems finds that inconsistency LAs represent around 5% of program elements and are detected with 72% precision. The existence of LAs can cause unnecessary effort to understand code and promote wrong assumptions, so awareness of them is important. Further study of developer opinions and impacts is needed along with potential solutions.
1. CSMR’13
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, Canada
2 University of Sannio, Benevento, Italy
1
3. Venera Arnaoudova CSMR’13
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]
4. Venera Arnaoudova CSMR’13
• 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
5. Venera Arnaoudova CSMR’13
• 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
6. Venera Arnaoudova CSMR’13
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
7. Venera Arnaoudova CSMR’13
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
8. Venera Arnaoudova CSMR’13
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
9. Venera Arnaoudova CSMR’13
• 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
10. Venera Arnaoudova CSMR’13
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
11. Venera Arnaoudova CSMR’13
• Inconsistency between a program entity’s
• documentation (i.e., comments)
• name
• behaviour (type, implementation)
8
Inconsistency LAs
12. Venera Arnaoudova CSMR’13
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!
13. Venera Arnaoudova CSMR’13
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!
14. Venera Arnaoudova CSMR’13
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!
15. Venera Arnaoudova CSMR’13
Does more than it says
Says more than it does
Does the opposite
Method signature and comment are opposite
Method name and return type are opposite
Behaviour
Inconsistency LAs
12
Others trust what you say!
16. Venera Arnaoudova CSMR’13
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
17. Venera Arnaoudova CSMR’13
Study
• Prototype detector: LAPD
• RQ:To what extent LAs exist?
• Context: System Version Methods Attributes
ArgoUML
0.10.1 5 K 3 K
ArgoUML
0.34 11 K 6 K
Cocoon 2.2.0 4 K 3 K
Eclipse 1.0 36 K 22 K
14
18. Venera Arnaoudova CSMR’13
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
Detected
wrt the
population
194 0.35%
1016 1.82%
288 0.52%
Detected
wrt the
population
438 1.3%
302 0.89%
24 0.07%
15
19. Venera Arnaoudova CSMR’13
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%
20. Venera Arnaoudova CSMR’13
To summarize
• Defined Inconsistency LAs
• Prototype detection tool - LAPD
• 72% precision
• Inconsistency LAs represent 5% of the
studied systems
17
21. Venera Arnaoudova CSMR’13
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
23. Venera Arnaoudova CSMR’13
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?