More Related Content Similar to FASE08.ppt (20) More from Ptidej Team (20) FASE08.ppt1. A Domain Analysis to Specify Design
Defects and Generate Detection Algorithms
Naouel Moha, Yann-Gaël Guéhéneuc,
Anne-Françoise Le Meur, Laurence Duchien
Ptidej Team, GEODES, Université de Montréal, Canada
LIFL, INRIA Lille - Nord Europe / ADAM Team, Université de Lille, France
FASE’08
29 March - 6 April, 2008
2. Context
Moha © A Domain Analysis to Specify Design Defects and Generate Detection Algorithms 2
3. Context
Moha © A Domain Analysis to Specify Design Defects and Generate Detection Algorithms 3
4. What Kind of Defects ?
Design Patterns are “good” solutions to recurring design problems
Design Defects (DDs)
are “bad” solutions to recurring problems
2 categories:
High-level (global) problems: antipatterns [Brown 98]
Low-level (local) problems: code smells* [Fowler 99]
“ deviations from specifications or expectations which might lead to
≠
failures in operation ”
* Some code smells can be considered as high-level DDs
Moha © A Domain Analysis to Specify Design Defects and Generate Detection Algorithms 4
5. What Kind of Defects ?
2 examples of high-level DDs [Brown 98]
Blob (God Class)
“ Procedural-style design leads to one object with a
lion’s share of the responsibilities while most other
objects only hold data or execute simple processes ”
Large controller class
Many fields and methods with a low cohesion*
Dependent on the data stored in associated
data classes
*How closely the methods are related to the instance
variables in the class.
Moha © A Domain Analysis to Specify Design Defects and Generate Detection Algorithms 5
6. What Kind of Defects ?
2 examples of high-level DDs [Brown 98]
Spaghetti Code
“ Ad hoc software structure makes it difficult to extend
and optimize code. ”
Procedural thinking in OO programming
Lack of structure : no inheritance, no reuse, no
polymorphism
Long methods process oriented with no
parameters and low cohesion
Classes with procedural names
Use of global variables for processing
Moha © A Domain Analysis to Specify Design Defects and Generate Detection Algorithms 6
7. Method DECOR
Specification
Processing
Validation
Detection
Analysis
Domain
Moha © A Domain Analysis to Specify Design Defects and Generate Detection Algorithms 7
8. Method DECOR
Specification
Processing
Validation
Detection
Analysis
Domain
Moha © A Domain Analysis to Specify Design Defects and Generate Detection Algorithms 8
9. Method DECOR
Specification
Processing
Validation
Detection
Analysis
Domain
Contributions
Domain analysis of DDs and domain-specific language
Explicit process for the specifications
Validation : first study on both precision and recall
Moha © A Domain Analysis to Specify Design Defects and Generate Detection Algorithms 9
10. Method DECOR
Specification
Processing
Validation
Detection
Analysis
Domain
Moha © A Domain Analysis to Specify Design Defects and Generate Detection Algorithms 10
11. DECOR Method
Domain Analysis
On all defects On each defect On each system
Source code Source code
1 2 3 4 5
Specification
of the system of the system
Processing
Validation
Vocabulary
Detection
Analysis
Domain
Text-based descriptions Specifications Operational Suspicious Classes having
of design defects specifications classes design defects
Taxonomy
Brown et al. (1998)
Demeyer (2002)
Dudney (2003)
Marinescu (2004) Marinescu (2004)
Fowler (1999) Marinescu (2004)
Alikacem (2006) Munro (2005)
Riel (1996) Munro (2005)
Travassos : manual detection (1999)
Webster (1995) Alikacem (2006)
Tools: SmallLint, PMD, CROCOPAT
The Spaghetti Code is an
antipattern that is characteristic
Chapter 1 of procedural thinking in object-
oriented programming. Spaghetti
Code is revealed by classes with
Descriptions of antipatterns no structure, declaring long
methods with no parameters,
and utilising global variables for
processing. Names of classes
and methods may suggest
procedural programming.
Spaghetti Code does not exploit
and prevents the use of object-
orientation mechanisms,
polymorphism and inheritance.
Moha © A Domain Analysis to Specify Design Defects and Generate Detection Algorithms 11
12. DECOR Method
Domain Analysis
On all defects On each defect On each system
Source code Source code
1 2 3 4 5
Specification
of the system of the system
Processing
Validation
Vocabulary
Detection
Analysis
Domain
Text-based descriptions Specifications Operational Suspicious Classes having
of design defects specifications classes design defects
Taxonomy
Brown et al. (1998)
Demeyer (2002)
Dudney (2003)
Marinescu (2004) Marinescu (2004)
Fowler (1999) Marinescu (2004)
Alikacem (2006) Munro (2005)
Riel (1996) Munro (2005)
Travassos : manual detection (1999)
Webster (1995) Alikacem (2006)
Tools: SmallLint, PMD, CROCOPAT
The Spaghetti Code is an
antipattern that is characteristic
Chapter 1 of procedural thinking in object-
oriented programming. Spaghetti
Code is revealed by classes with
Descriptions of antipatterns no structure, declaring long
methods with no parameters,
and utilising global variables for
Identification of Key Concepts processing. Names of classes
and methods may suggest
procedural programming.
Spaghetti Code does not exploit
and prevents the use of object-
orientation mechanisms,
polymorphism and inheritance.
Moha © A Domain Analysis to Specify Design Defects and Generate Detection Algorithms 12
13. DECOR Method
Domain Analysis
On all defects On each defect On each system
Source code Source code
1 2 3 4 5
Specification
of the system of the system
Processing
Validation
Vocabulary
Detection
Analysis
Domain
Text-based descriptions Specifications Operational Suspicious Classes having
of design defects specifications classes design defects
Taxonomy
Brown et al. (1998)
Demeyer (2002)
Dudney (2003)
Marinescu (2004) Marinescu (2004)
Fowler (1999) Marinescu (2004)
Alikacem (2006) Munro (2005)
Riel (1996) Munro (2005)
Travassos : manual detection (1999)
Webster (1995) Alikacem (2006)
Tools: SmallLint, PMD, CROCOPAT
Moha © A Domain Analysis to Specify Design Defects and Generate Detection Algorithms 13
14. DECOR Method
Domain Analysis
On all defects On each defect On each system
Source code Source code
1 2 3 4 5
Specification
of the system of the system
Processing
Validation
Vocabulary
Detection
Analysis
Domain
Text-based descriptions Specifications Operational Suspicious Classes having
of design defects specifications classes design defects
Taxonomy
Brown et al. (1998)
Demeyer (2002)
Dudney (2003)
Marinescu (2004) Marinescu (2004)
Fowler (1999) Marinescu (2004)
Alikacem (2006) Munro (2005)
Riel (1996) Munro (2005)
Travassos : manual detection (1999)
Webster (1995) Alikacem (2006)
Tools: SmallLint, PMD, CROCOPAT
Moha © A Domain Analysis to Specify Design Defects and Generate Detection Algorithms 14
15. Method DECOR
Specification
Processing
Validation
Detection
Analysis
Domain
Moha © A Domain Analysis to Specify Design Defects and Generate Detection Algorithms 15
16. DECOR Method
Specifications
On all defects On each defect On each system
Source code Source code
1 2 3 4 5
Specification
of the system of the system
Processing
Validation
Vocabulary
Detection
Analysis
Domain
Text-based descriptions Specifications Operational Suspicious Classes having
of design defects specifications classes design defects
Taxonomy
Brown et al. (1998)
Demeyer (2002)
Dudney (2003)
Marinescu (2004) Marinescu (2004)
Fowler (1999) Marinescu (2004)
Alikacem (2006) Munro (2005)
Riel (1996) Munro (2005)
Travassos : manual detection (1999)
Webster (1995) Alikacem (2006)
Tools: SmallLint, PMD, CROCOPAT
SADSL (Software Architectural Defect Specification Language)
Language based on a meta-model for specifying DDs
CODESMELL define LongMethod as METRIC LOC_METHOD with VERY HIGH and 10.0 ;
CODESMELL define NoParameter as METRIC NMNOPARAM with VERY HIGH and 5.0 ;
CODESMELL define NoInheritance as METRIC DIT with 1 and 0.0 ;
CODESMELL define NoPolymorphism as STRUC NO_POLYMORPHISM ;
CODESMELL define ProceduralName as LEXIC CLASS_NAME with (Make, Create, Exec) ;
CODESMELL define GlobalVariable as STRUC USE_GLOBAL_VARIABLE ;
ANTIPATTERN define SpaghettiCode as {
((LongMethod INTER NoParameter) INTER (NoInheritance UNION NoPolymorphism))
INTER
(ProceduralName UNION UseGlobalVariable) } ;
Moha © A Domain Analysis to Specify Design Defects and Generate Detection Algorithms 16
17. DECOR Method
Specifications
On all defects On each defect On each system
Source code Source code
1 2 3 4 5
Specification
of the system of the system
Processing
Validation
Vocabulary
Detection
Analysis
Domain
Text-based descriptions Specifications Operational Suspicious Classes having
of design defects specifications classes design defects
Taxonomy
Brown et al. (1998)
Demeyer (2002)
Dudney (2003)
Marinescu (2004) Marinescu (2004)
Fowler (1999) Marinescu (2004)
Alikacem (2006) Munro (2005)
Riel (1996) Munro (2005)
Travassos : manual detection (1999)
Webster (1995) Alikacem (2006)
Tools: SmallLint, PMD, CROCOPAT
SADSL (Software Architectural Defect Specification Language)
Language based on a meta-model for specifying DDs
CODESMELL define LongMethod as METRIC LOC_METHOD with VERY HIGH and 10.0 ;
CODESMELL define NoParameter as METRIC NMNOPARAM with VERY HIGH and 5.0 ;
CODESMELL define NoInheritance as METRIC DIT with 1 and 0.0 ;
CODESMELL define NoPolymorphism as STRUC NO_POLYMORPHISM ;
CODESMELL define ProceduralName as LEXIC CLASS_NAME with (Make, Create, Exec) ;
CODESMELL define GlobalVariable as STRUC USE_GLOBAL_VARIABLE ;
ANTIPATTERN define SpaghettiCode as {
((LongMethod INTER NoParameter) INTER (NoInheritance UNION NoPolymorphism))
INTER
(ProceduralName UNION UseGlobalVariable) } ;
Moha © A Domain Analysis to Specify Design Defects and Generate Detection Algorithms 17
18. DECOR Method
Specifications
On all defects On each defect On each system
Source code Source code
1 2 3 4 5
Specification
of the system of the system
Processing
Validation
Vocabulary
Detection
Analysis
Domain
Text-based descriptions Specifications Operational Suspicious Classes having
of design defects specifications classes design defects
Taxonomy
Brown et al. (1998)
Demeyer (2002)
Dudney (2003)
Marinescu (2004) Marinescu (2004)
Fowler (1999) Marinescu (2004)
Alikacem (2006) Munro (2005)
Riel (1996) Munro (2005)
Travassos : manual detection (1999)
Webster (1995) Alikacem (2006)
Tools: SmallLint, PMD, CROCOPAT
Meta-model SADDL (Software Architectural Defect Definition Language)
Moha © A Domain Analysis to Specify Design Defects and Generate Detection Algorithms 18
19. Method DECOR
Specification
Processing
Validation
Detection
Analysis
Domain
Moha © A Domain Analysis to Specify Design Defects and Generate Detection Algorithms 19
20. Method DECOR
Specification
Generation
Validation
Algorithm
Detection
Analysis
Domain
Moha © A Domain Analysis to Specify Design Defects and Generate Detection Algorithms 20
21. DECOR Method
Algorithm Generation
On all defects On each defect On each system
Source code Source code
1 2 3 4 5
Specification
of the system of the system
Processing
Validation
Vocabulary
Detection
Analysis
Domain
Text-based descriptions Specifications Operational Suspicious Classes having
of design defects specifications classes design defects
Taxonomy
Brown et al. (1998)
Demeyer (2002)
Dudney (2003)
Marinescu (2004) Marinescu (2004)
Fowler (1999) Marinescu (2004)
Alikacem (2006) Munro (2005)
Riel (1996) Munro (2005)
Travassos : manual detection (1999)
Webster (1995) Alikacem (2006)
Tools: SmallLint, PMD, CROCOPAT
Moha © A Domain Analysis to Specify Design Defects and Generate Detection Algorithms 21
22. DECOR Method
Algorithm Generation
On all defects On each defect On each system
Source code Source code
1 2 3 4 5
Specification
of the system of the system
Processing
Validation
Vocabulary
Detection
Analysis
Domain
Text-based descriptions Specifications Operational Suspicious Classes having
of design defects specifications classes design defects
Taxonomy
Brown et al. (1998)
Demeyer (2002)
Dudney (2003)
Marinescu (2004) Marinescu (2004)
Fowler (1999) Marinescu (2004)
Alikacem (2006) Munro (2005)
Riel (1996) Munro (2005)
Travassos : manual detection (1999)
Webster (1995) Alikacem (2006)
Tools: SmallLint, PMD, CROCOPAT
Moha © A Domain Analysis to Specify Design Defects and Generate Detection Algorithms 22
23. DECOR Method
Algorithm Generation
On all defects On each defect On each system
Source code Source code
1 2 3 4 5
Specification
of the system of the system
Processing
Validation
Vocabulary
Detection
Analysis
Domain
Text-based descriptions Specifications Operational Suspicious Classes having
of design defects specifications classes design defects
Taxonomy
Brown et al. (1998)
Demeyer (2002)
Dudney (2003)
Marinescu (2004) Marinescu (2004)
Fowler (1999) Marinescu (2004)
Alikacem (2006) Munro (2005)
Riel (1996) Munro (2005)
Travassos : manual detection (1999)
Webster (1995) Alikacem (2006)
Tools: SmallLint, PMD, CROCOPAT
Consistency and domain-specific analyses
- Verify that specifications are not inconsistent, redundant,
or incomplete
- Ex: 2 rules with same names but different properties
2 rules with different names but identical properties
Moha © A Domain Analysis to Specify Design Defects and Generate Detection Algorithms 23
24. DECOR Method
Algorithm Generation
On all defects On each defect On each system
Source code Source code
1 2 3 4 5
Specification
of the system of the system
Processing
Validation
Vocabulary
Detection
Analysis
Domain
Text-based descriptions Specifications Operational Suspicious Classes having
of design defects specifications classes design defects
Taxonomy
Brown et al. (1998)
Demeyer (2002)
Dudney (2003)
Marinescu (2004) Marinescu (2004)
Fowler (1999) Marinescu (2004)
Alikacem (2006) Munro (2005)
Riel (1996) Munro (2005)
Travassos : manual detection (1999)
Webster (1995) Alikacem (2006)
Tools: SmallLint, PMD, CROCOPAT
Complexity : O((c+op) X n) SAD Framework
c : number of properties - Meta-model to represent OO programs
op : number of operators - Repository of metrics
n : number of classes
- Services to analyse structural relationships
- Services to perform structural and lexical analyses
Moha © A Domain Analysis to Specify Design Defects and Generate Detection Algorithms 24
25. DECOR Method
Algorithm Generation
On all defects On each defect On each system
Source code Source code
1 2 3 4 5
Specification
of the system of the system
Processing
Validation
Vocabulary
Detection
Analysis
Domain
Text-based descriptions Specifications Operational Suspicious Classes having
of design defects specifications classes design defects
Taxonomy
Brown et al. (1998)
Demeyer (2002)
Dudney (2003)
Marinescu (2004) Marinescu (2004)
Fowler (1999) Marinescu (2004)
Alikacem (2006) Munro (2005)
Riel (1996) Munro (2005)
Travassos : manual detection (1999)
Webster (1995) Alikacem (2006)
Tools: SmallLint, PMD, CROCOPAT
1 public class <CODESMELL>Detection
2 extends CodeSmellDetection
3 implements ICodeSmellDetection {
4 public Set performDetection() {
5 IClass c = iteratorOnClasses.next();
6 LOCofSetOfClasses.add(
7 Metrics.compute(<METRIC>, c));
8 ...
9 BoxPlot boxPlot = new BoxPlot(
10 <METRIC>ofSetOfClasses, <FUZZINESS>);
11 Map setOfOutliers =
12 boxPlot.<ORDINAL_VALUE>();
13 ...
14 suspiciousCodeSmells.add( new CodeSmell(
15 <CODESMELL>, setOfOutliers));
16 ...
17 return suspiciousCodeSmells;
18 }
Visitor Template
Moha © A Domain Analysis to Specify Design Defects and Generate Detection Algorithms 25
26. DECOR Method
Algorithm Generation
On all defects On each defect On each system
Source code Source code
1 2 3 4 5
Specification
of the system of the system
Processing
Validation
Vocabulary
Detection
Analysis
Domain
Text-based descriptions Specifications Operational Suspicious Classes having
of design defects specifications classes design defects
Taxonomy
Brown et al. (1998)
Demeyer (2002)
Dudney (2003)
Marinescu (2004) Marinescu (2004)
Fowler (1999) Marinescu (2004)
Alikacem (2006) Munro (2005)
Riel (1996) Munro (2005)
Travassos : manual detection (1999)
Webster (1995) Alikacem (2006)
Tools: SmallLint, PMD, CROCOPAT
Visitor Generated Code
Moha © A Domain Analysis to Specify Design Defects and Generate Detection Algorithms 26
27. Method DECOR
Specification
Processing
Validation
Detection
Analysis
Domain
Moha © A Domain Analysis to Specify Design Defects and Generate Detection Algorithms 27
28. Method DECOR
Specification
Processing
Validation
Detection
Analysis
Domain
Moha © A Domain Analysis to Specify Design Defects and Generate Detection Algorithms 28
29. DECOR Method
Experiments
On all defects On each defect On each system
Source code Source code
1 2 3 4 5
Specification
of the system of the system
Processing
Validation
Vocabulary
Detection
Analysis
Domain
Text-based descriptions Specifications Operational Suspicious Classes having
of design defects specifications classes design defects
Taxonomy
Brown et al. (1998)
Demeyer (2002)
Dudney (2003)
Marinescu (2004) Marinescu (2004)
Fowler (1999) Marinescu (2004)
Alikacem (2006) Munro (2005)
Riel (1996) Munro (2005)
Travassos : manual detection (1999)
Webster (1995) Alikacem (2006)
Tools: SmallLint, PMD, CROCOPAT
Goal : Validate the generated algorithms in terms of precision and recall
Xerces: 71,217 LOC, 513 classes and 162 interfaces
Nb of Existing Detected Detection
Defects Precision Recall
classes Defects Defects Time
Blob 39 (7,6%) 44 (8,6%) 88,6% 100% 2,45s
Functional Decomp. 15 (2,9%) 29 (5,6%) 51,7% 100% 0,91s
513
Spaghetti Code 46 (9,0%) 76 (14,8%) 60,5% 100% 0,23s
Swiss Army Knife 23 (4,5%) 56 (10,9%) 41,1% 100% 0,08s
Moha © A Domain Analysis to Specify Design Defects and Generate Detection Algorithms 29
30. Demonstration
Moha © A Domain Analysis to Specify Design Defects and Generate Detection Algorithms 30
31. Conclusion
Method DECOR
Automate the generation of detection algorithms from specifications
written using a domain-specific language
Contributions
The domain-specific language defined from a domain analysis
Explicit process for the generation of detection algorithms
Validation in terms of precision and recall
Future Work
Experiments on other systems and defects
Comparison with existing approaches
Correction of defects (in progress)
Moha © A Domain Analysis to Specify Design Defects and Generate Detection Algorithms 31
32. Questions
Contact: mohanaou@iro.umontreal.ca
http://www-etud.iro.umontreal.ca/~mohanaou
Thanks for your attention !
Moha © A Domain Analysis to Specify Design Defects and Generate Detection Algorithms 32
33. DECOR Method
Algorithm Generation
On all defects On each defect On each system
Source code Source code
1 2 3 4 5
Specification
of the system of the system
Processing
Validation
Vocabulary
Detection
Analysis
Domain
Text-based descriptions Specifications Operational Suspicious Classes having
of design defects specifications classes design defects
Taxonomy
Brown et al. (1998)
Demeyer (2002)
Dudney (2003)
Marinescu (2004) Marinescu (2004)
Fowler (1999) Marinescu (2004)
Alikacem (2006) Munro (2005)
Riel (1996) Munro (2005)
Travassos : manual detection (1999)
Webster (1995) Alikacem (2006)
Tools: SmallLint, PMD, CROCOPAT
Box-plot for metrics with ordinal values
Moha © A Domain Analysis to Specify Design Defects and Generate Detection Algorithms 33