qsic09.ppt

28
Foutse Khomh, Stéphane Vaucher, Yann-Gaël Guéhéneuc , and Houari Sahraoui © Khomh, 2009 Ptidej Team – Pattern-based Quality Evaluation and Enhancement Department of Computer Engineering and Software Engineering École Polytechnique de Montréal, Québec, Canada A Bayesian Approach for the Detection of Code and Design Smells QSIC’09 Jeju-do 2009/08/25

Upload: ptidej-team

Post on 24-Jun-2015

93 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: QSIC09.ppt

Foutse Khomh, Stéphane Vaucher, Yann-Gaël Guéhéneuc, and Houari Sahraoui

© Khomh, 2009

Ptidej Team – Pattern-based Quality Evaluation and Enhancement

Department of Computer Engineering and Software EngineeringÉcole Polytechnique de Montréal, Québec, Canada

A Bayesian Approach for

the Detection of Code

and Design Smells

QSIC’09Jeju-do

2009/08/25

Page 2: QSIC09.ppt

2/27

Outline

� Motivation� Context� Problems and Objectives� Previous Work� Our Solution� Bayesian Belief Networks� Experiments� Discussions� Conclusion

Page 3: QSIC09.ppt

3/27

Motivation

� Independent IV&V team reviews of object-oriented software programs– Assess the quality of programs– Identify potential problems

• Defects• Anomalies• “Bad Smells”

Page 4: QSIC09.ppt

4/27

Context

� Code smells and antipatterns

� Blob: also called God class [23], is a class that centralises functionality and has too many responsibilities. Brown et al. [4] characterise its structure as a large controller class that depends on data stored in several surrounding data classes

Page 5: QSIC09.ppt

5/27

Problems and Objectives

� Problem 1: Sizes of programs can be large� Automate the evaluation process

� Problem 2: Resources are limited� Prioritise manual reviews

� Problem 3: Quality assessment is subjective� Consider uncertainty in the process

Page 6: QSIC09.ppt

6/27

Previous Work (1/2)

� Webster’s book on “antipatterns” [31]

� Riel’s 61 heuristics [23]

� Beck’s 22 code smells [11]

� Brown et al. 40 antipatterns [4]

� Travassos et al. manual approach [28]

� Marinescu’s detection strategies [17]

(also Munro [19])� Moha et al. rules cards in DECOR [18]

Page 7: QSIC09.ppt

7/27

Previous Work (2/2)

� Either no full automation– Problem 1 is not solved

� Or strict rules with classes participating or not (binary value) to an antipattern– Problem 2 and 3 are not solved

Page 8: QSIC09.ppt

8/27

Our Solution (1/2)

� Assign a probability that a class is considered an antipattern by a stakeholder

� Guide a manual inspection according to this probability

� Use Bayesian belief network to build a model of an antipattern and assign a probability to all classes

Page 9: QSIC09.ppt

9/27

Our Solution (2/2)

� Problem 1: Sizes of programs can be large� Assign a probability to all classes of interest

automatically

� Problem 2: Resources are limited� Prioritise manual reviews using probabilities

� Problem 3: Quality assessment is subjective� Uncertainty is naturally considered using

Bayesian beliefs networks

Page 10: QSIC09.ppt

10/27

BBN (1/3)

� A Bayesian Belief Network is a directed acyclic graph with probability distribution

� Graph structure – Nodes = random variables– Edges = probabilities dependencies

� Each node depends only on its parents

� Embody the experts’ knowledge

Page 11: QSIC09.ppt

11/27

BBN (2/3)

� Classifier– C = {smell, not smell}

� Input vector describing a class– <a1, …, an>– P(A|B) = P(B|A) P(A) / P(B)

Page 12: QSIC09.ppt

12/27

BBN (2/3)

� Building a BBN1. Define its structure2. Assign/learn its probability tables

Page 13: QSIC09.ppt

13/27

1. Defining the BBN Structure

� Based on Moha et al.’s rule cards

– Detection relies on metrics, binary class relations, and linguistic analysis

– Values are combined using set operators– Thresholds are statistically defined

(using a box plot)

Page 14: QSIC09.ppt

14/27

Rule Card of Blob

RULE_CARD : Blob {

RULE : Blob { ASSOC : a s s o c i a t e d FROM : m ai n Cl a ss ONE TO : D a t a C l a s s MANY } ;

RULE : MainClass { UNION LargeCla ssLowCohesion C o n t r o l l e r C l a s s } ;

RULE : LargeCla ssLo wCohesion { UNION L a r g e C l a s s LowCohesion } ;RULE : L a r g e C l a s s { ( METRIC : NMD + NAD, VERY_HIGH , 0 ) } ;

RULE : LowCohesion { ( METRIC : LCOM5, VERY_HIGH , 2 0 ) } ;

RULE : C o n t r o l l e r C l a s s { UNION( SEMANTIC : METHODNAME , { P r o c e s s , C o n t r o l , C t r l , Command , Cmd,

Proc, UI, Manage, D r i v e } )

( SEMANTIC : CLASSNAME , { P r o c e s s , C o n t r o l , C t r l , Command , Cmd,

Proc , UI, Manage, Drive , System, Subsystem } ) } ;RULE : D a t a C l a s s { ( STRUCT : METHOD_ACCESSOR , 9 0 ) } ;

};

Page 15: QSIC09.ppt

15/27

Conversion into BBN

� Set operators (OR, AND) are learned using conditional probabilities

� Hard thresholds and rules are smoothed by interpolating values

� Binary class relations are counted and treated as metrics

Page 16: QSIC09.ppt

16/27

BBN Structure for the Blob

Page 17: QSIC09.ppt

17/27

2. Resulting BBN for the Blob

Page 18: QSIC09.ppt

18/27

Experiments

� RQ1: To what extent a model built with a BBN based on an existing rule-based model is able detect smells in a program?

� RQ2: Is a model built with a BBN better than a state-of-the-art approach, DECOR?

Page 19: QSIC09.ppt

19/27

Settings

� Programs– Xerces v2.7.0– Gantt Project v1.10.2

� Oracle: Vote of three groups (of students) on both programs

Page 20: QSIC09.ppt

20/27

Settings

� Calibration (probability tables)– Local (same-system calibration)– External (calibrated on one system,

applied to the other)

Page 21: QSIC09.ppt

21/27

Local calibration

� On Xerces only� Three-fold cross validation

– 3 groups with 5 Blobs in each– Combination of 2 groups for calibration,

tested on the other

Inspected Classes

Group1 6

Group2 7

Group3 9

Waste of 8% to 44%

of effort (average 32%)

Page 22: QSIC09.ppt

22/27

External calibration

� Probabilities learned on one, applied on other� Precision vs. Recall (per investigation sizes)� Xerces (left), Gantt (right)

Page 23: QSIC09.ppt

23/27

Experiments

� RQ1: To what extent a model built with a BBN based on an existing rule-based model is able detect smells in a program?

� RQ2: Is a model built with a BBN better than a state-of-the-art approach, DECOR?

� Better than DECOR

Page 24: QSIC09.ppt

24/27

Discussions (1/2)

� Results of BBN are superior to those of DECOR

� External calibration yields good results even though tweaking is recommended

� A well calibrated model should be able to estimate the number of smells in a program, but our models overestimate by a factor of 2

Page 25: QSIC09.ppt

25/27

Discussions (2/2)

� Used simple techniques to convert rules into probability distributions

� Worked with discrete probabilities, might need to be adapted to continuous cases

Page 26: QSIC09.ppt

26/27

Conclusion

� Bayesian models support uncertainty in detection process

� Their performance is better than state-of-the-art rules

� External calibration seems to indicate that this could be used in an industrial context with minimal costs

� Support for automated conversion of rules to support more design smells

Page 27: QSIC09.ppt

27/27

Acknowledgements

� Naouel Moha for providing her data and code to compare with DECOR

� Natural Sciences and Engineering Research Council of Canada

� Canada Research Chair in Software Patterns and Patterns of Software

Page 28: QSIC09.ppt

28/27

Advertisement

� IEEE Software� Special issue on Software Evolution

� Deadline: 1st of November, 2009� Publication: July/August 2010

� Please do not hesitate to contact me! ☺