Presentation is loading. Please wait.

Presentation is loading. Please wait.

Software Quality Improvements from Removing Code Smells Wes J. Lloyd July 15, 2008 Computer Science Department Colorado State University Dr. Sudipto Ghosh,

Similar presentations


Presentation on theme: "Software Quality Improvements from Removing Code Smells Wes J. Lloyd July 15, 2008 Computer Science Department Colorado State University Dr. Sudipto Ghosh,"— Presentation transcript:

1 Software Quality Improvements from Removing Code Smells Wes J. Lloyd July 15, 2008 Computer Science Department Colorado State University Dr. Sudipto Ghosh, co-advisor Dr. James Bieman, co-advisor

2 2 Background Object Modelling System (OMS) Framework Object Modelling System (OMS) Framework Java OO framework for scientific modellingJava OO framework for scientific modelling Models disaggregated into componentsModels disaggregated into components How can we help developers improve component reusability? How can we help developers improve component reusability? Reuse components across multiple models Reuse components across multiple models Support plug-and-play to try out different modelling approaches, scientific equations, etc. Support plug-and-play to try out different modelling approaches, scientific equations, etc.

3 3 Evapotranspiration Harmon equation Penman-Monteith equation Blaney-Criddle equation Makkink equation Hargreaves formula eddy covariance technique Potential evapotranspiration (PET)

4 4 Code Inspection How can we help developers improve component reusability? How can we help developers improve component reusability? OMS Code Inspection plug-in toolOMS Code Inspection plug-in tool Inspect “quality” of components Inspect “quality” of components Encourage design best practices Encourage design best practices But what should the tool look for?But what should the tool look for? What sort of problems? What sort of problems? How to quantify reusability? How to quantify reusability? Many static analysis tools already exist Many static analysis tools already exist

5 5 Code Smells A symptom in source code that is indicative of a problem A symptom in source code that is indicative of a problem Poor software designPoor software design Abuse of OO language featuresAbuse of OO language features Misunderstanding of OO language featuresMisunderstanding of OO language features Code smells suggest areas to refactor Code smells suggest areas to refactor Twenty-two common smells identified by Martin Fowler in Refactoring: Improving the Design of Existing Code 2 Twenty-two common smells identified by Martin Fowler in Refactoring: Improving the Design of Existing Code 2

6 6 Detecting Code Smells Most smells conform to one of three types of smell detection Most smells conform to one of three types of smell detection Type 0 – Manual InspectionType 0 – Manual Inspection Type 1 – Tool supported manual inspectionType 1 – Tool supported manual inspection Tool finds area of interest in code Tool finds area of interest in code Type 2 – Tool supported detection by thresholdType 2 – Tool supported detection by threshold

7 7 Detecting Code Smells - 2 Type 0 - manual code inspection Type 0 - manual code inspection Divergent ChangeDivergent Change Shotgun SurgeryShotgun Surgery Incomplete Class LibraryIncomplete Class Library Alternate Classes with Different InterfacesAlternate Classes with Different Interfaces

8 8 Detecting Code Smells - 3 Type 1 - Tools suggest locations Type 1 - Tools suggest locations based on various thresholds/criteriabased on various thresholds/criteria Programmer’s intent can not be automatically determinedProgrammer’s intent can not be automatically determined Detection is subjectiveDetection is subjective (too many) Comments (too many) Comments Refused Bequest Refused Bequest Temporary Field Temporary Field Speculative Generality Speculative Generality

9 9 Detecting Code Smells - 4 Type 2 - smells detectable by threshold Type 2 - smells detectable by threshold Long MethodLong Method Large ClassLarge Class Long Parameter ListLong Parameter List Lazy ClassLazy Class Duplicate CodeDuplicate Code Others...Others...

10 10 Research Questions Is the presence of code smells indicative of poor reusability? Is the presence of code smells indicative of poor reusability? Which code smells indicate poor reusability? Which code smells indicate poor reusability?

11 11 Reusability Assessment Assessment of any software quality attribute is highly subjective Assessment of any software quality attribute is highly subjective Many different reusability assessment approaches 4, 9, 10, 11, 12 Many different reusability assessment approaches 4, 9, 10, 11, 12

12 12 Reusability Assessment Validate metrics with Validate metrics with human evaluators assessmentshuman evaluators assessments classes designed with specific reusability attributesclasses designed with specific reusability attributes highly reused library classes (Java SDK, etc.)highly reused library classes (Java SDK, etc.) large organizational codebases with abundant reuse instanceslarge organizational codebases with abundant reuse instances empirical study. Provide class library to developers with programming tasks. Investigate attributes of reused classesempirical study. Provide class library to developers with programming tasks. Investigate attributes of reused classes

13 13 Initial Investigation How are traditional OO metrics affected by presence of code smells? How are traditional OO metrics affected by presence of code smells? Chidamber and Kemerer OO metrics 1Chidamber and Kemerer OO metrics 1 Does smell removal indicate quality improvements? Does smell removal indicate quality improvements?

14 14 OO Metrics Coupling between object classes (CBO) ‏ Coupling between object classes (CBO) ‏ Response for a class (RFC) ‏ Response for a class (RFC) ‏ Lack of Cohesion in Methods (LCOM) ‏ Lack of Cohesion in Methods (LCOM) ‏ McCabe’s Cyclomatic Complexity (CC) ‏ McCabe’s Cyclomatic Complexity (CC) ‏

15 15 OO Java Models OMS Framework Models OMS Framework Models Precipitation-Runoff Modeling System (PRMS) ‏Precipitation-Runoff Modeling System (PRMS) ‏ Hydrology Model Hydrology Model 19 classes, 1012 methods, 4370 NCSS 19 classes, 1012 methods, 4370 NCSS CEAP/J2000CEAP/J2000 Hydrology Model Hydrology Model 51 classes, 216 methods, 3519 NCSS 51 classes, 216 methods, 3519 NCSS Java Model Java Model ACRU2000ACRU2000 Univ. of Florida Hydrology Model Univ. of Florida Hydrology Model 668 classes, 3088 methods, 20708 NCSS 668 classes, 3088 methods, 20708 NCSS

16 16 Static Analysis Tools JavaNCSS JavaNCSS http://www.kclee.de/clemens/java/javancss/http://www.kclee.de/clemens/java/javancss/ Checkstyle Checkstyle http://checkstyle.sourceforge.net/http://checkstyle.sourceforge.net/ Checkstyle Simian plugin Checkstyle Simian plugin http://www.redhillconsulting.com.au/products/simian/http://www.redhillconsulting.com.au/products/simian/ JHawk JHawk http://www.virtualmachinery.com/jhawkprod.htmhttp://www.virtualmachinery.com/jhawkprod.htm CKJM CKJM http://www.spinellis.gr/sw/ckjm/http://www.spinellis.gr/sw/ckjm/

17 17 Smell Detection Long Parameter List Long Parameter List # parameters >= 6# parameters >= 6 Large Classes Large Classes Class size > avg + 2 stdev NCSS (Non- Comment Source Statements) ‏Class size > avg + 2 stdev NCSS (Non- Comment Source Statements) ‏ # Methods > avg + 2 stdev# Methods > avg + 2 stdev Long Methods Long Methods Length > avg + 2 stdev NCSSLength > avg + 2 stdev NCSS Cyclomatic Complexity > avg + 2 stdevCyclomatic Complexity > avg + 2 stdev

18 18 Smell Detection - 2 Duplicate Code Duplicate Code > 10 duplicate LOC> 10 duplicate LOC Lazy Classes Lazy Classes Class size < 8 NCSSClass size < 8 NCSS

19 19 Smell Detection - 3 34160 Lazy Classes 1332810 Duplicate Code 63165 Long Methods 2631 Large Classes 27811 Long Parameter List ACRU2000CEAP/J2000PRMSSmell

20 20 ACRU2000 - Lazy Classes ACRU2000- 341 – –51% of classes < 8 NCSS (341 classes)‏ – –54% of classes < 4 methods (364 classes)‏ – –61% of classes w/ avg method length <= 2 NCSS (409 classes)‏

21 21 Lazy Class Refactoring Does the presence of the Lazy Class Smell in ACRU2000 affect OO metrics? Does the presence of the Lazy Class Smell in ACRU2000 affect OO metrics? Refactored smallest classes first Refactored smallest classes first 2, 3, 4, 5, 6, 7 NCSS2, 3, 4, 5, 6, 7 NCSS Model produces same output with test data set after each refactoring Model produces same output with test data set after each refactoring Refactored versions saved in Subversion Refactored versions saved in Subversion Enable future analysisEnable future analysis

22 22 Lazy Class Refactoring - 2 18173223011333 7 line classes removed 182262254236344 6 line classes removed 19183296316580 5 line classes removed 19225298032596 4 line classes removed 19272304430628 3 line classes removed 20108307810658 2 line classes removed 2013830880668 Original Code StatementsMethodsClasses Removed # ClassesRefactoring

23 23 Lazy Class Causes 13Unused Class 3Class with little code 4Empty child class (no code)‏ 7Non-abstract class /w only abstract methods 8Empty class used for tracking type 10Abstract class with little/no code 16Data class: not used 27Exception Class with no functionality 249Data class: extension instead of instantiation

24 24 Summary of Results # of classes reduced ~ 50% # of classes reduced ~ 50% # of methods decreased ~ 28% # of methods decreased ~ 28% # of statements decreases ~ 10% # of statements decreases ~ 10% Refactored code becomes functionally more dense Refactored code becomes functionally more dense Class average cyclomatic complexity increasesClass average cyclomatic complexity increases Class Average response for a class increasesClass Average response for a class increases Coupling/Cohesion Coupling/Cohesion Class average coupling decreasesClass average coupling decreases Class average LCOM no significant changeClass average LCOM no significant change

25 25 Coupling (CBO)‏ 3.39 7 line classes removed 3.023.34 6 line classes removed 3.021.98 5 line classes removed 3.001.92 4 line classes removed 2.991.82 3 line classes removed 3.652.42 2 line classes removed 3.652.38 Original Code Average CBO w/o lazy classes Average CBO all classes Refactoring

26 26 Coupling (CBO) - 2 5.58202 (60.66%)‏ 7 line classes removed 5.39213 (61.92%)‏ 6 line classes removed 5.39213 (36.72%)‏ 5 line classes removed 5.32215 (36.07%)‏ 4 line classes removed 5.33214 (34.08%)‏ 3 line classes removed 5.96267 (40.58%)‏ 2 line classes removed 5.96267 (39.97%)‏ Original Code Average CBO coupled classes # classes w/ coupling Refactoring

27 27 Lack of Cohesion (LCOM)‏ 0.300.3 7 line classes removed 0.300.29 6 line classes removed 0.300.18 5 line classes removed 0.290.17 4 line classes removed 0.290.16 3 line classes removed 0.290.15 2 line classes removed 0.290.15 Original Code Average LCOM w/o lazy classes Average LCOM all classes Refactoring

28 28 Total Cyclomatic Complexity (TCC)‏ 13.92 7 line classes removed 13.1413.53 6 line classes removed 13.149.25 5 line classes removed 13.079.03 4 line classes removed 13.058.66 3 line classes removed 13.058.31 2 line classes removed 13.058.21 Original Code Average TCC w/o lazy classes Average TCC all classes Refactoring

29 29 Response for a class (RFC)‏ 19.4 7 line classes removed 18.7418.87 6 line classes removed 18.7412.42 5 line classes removed 18.6112.09 4 line classes removed 18.5811.56 3 line classes removed 18.6311.1 2 line classes removed 18.6310.95 Original Code Average RFC w/o lazy classes Average RFC all classes Refactoring

30 30 Limitations “Data” and “process” objects instantiated dynamically at runtime based on input datafile “Data” and “process” objects instantiated dynamically at runtime based on input datafile These class uses not counted by static analysis toolsThese class uses not counted by static analysis tools Only (1) system analyzed Only (1) system analyzed Only (1) smell refactored Only (1) smell refactored Only (1) model test dataset Only (1) model test dataset

31 31 Future Work Data analysis Data analysis Box plots, distribution plotsBox plots, distribution plots Investigate other smells in ACRU2000 Investigate other smells in ACRU2000 Long Method, Large Class, Duplicate Code, Long Parameter ListLong Method, Large Class, Duplicate Code, Long Parameter List Investigate lazy class smell in other systems Investigate lazy class smell in other systems Investigate other smells in other systems Investigate other smells in other systems What hypotheses can be stated from exploratory studies? What hypotheses can be stated from exploratory studies? What relationships exist?What relationships exist?

32 32 Questions

33 33 References 1) Chidamber, S., Kemerer, C., A metrics suite for object oriented design. IEEE Transactions on Software Engineering, 20(6); 476-493, 1994. 2) Fowler, M., et al., Refactoring: Improving the Design of Existing Code: Addison-Wesley, 1999. 3) Emden, E., Moonen, L., Java Quality Assurance by Detecting Code Smells, in Proc. of the 9th Working Conference on Reverse Engineering (WCRE '02), 97-106, 2002. 4) Moser, R., Sillitti, A., Abrahamsson, P., Succi, G., Does refactoring improve reusability?, in Proc. 9th International Conference on Software Reuse (ICSR 2006), Lecture Notes in Computer Science, 4039: 287-297, 2006. 5) Price, M., Needham, D., Demurjian, S., Producing Reusable Object- Oriented Components: A Domain-and-Organization-Specific Perspective, in Proc. ACM Symposium on Software Reusability (SSR 2001), 41-50, 2001. 6) Mens, T., Deursen, A. V., Refactoring: Emerging Trends and Open Problems, in Proc. 1st International Workshop on Refactoring: Achievements, Challenges and Effects (REFACE 2003), 1-4, 2003.

34 34 References - 2 1) Munro, M., Product Metrics for Automatic Identification of Bad Smell Design Problems in Java Source-Code, in Proc. 11th IEEE International Software Metrics Symposium (METRICS 2005), 15-23, 2005. 2) Mantyla, M., Vanhanen, J., Lassenius, C., in Proc. 20th IEEE International Conference on Software Maintenance (ICSM '04), “Bad Smells – Humans as Code Critics”, 399-408, 2004. 3) Washizaki, H., Yamamoto, H., Fukazawa, Y., A Metrics Suite for Measuring Reusability of Software Components, in Proc. of the 9th International Software Metrics Symposum (METRICS '03), 2003. 4) Etzkorn, L. H., Hughes, W. E., Davis, C. G., Automated reusability quality analysis of OO legacy software, Information and Software Technology, Vol. 43, No. 5, Elsevier, 2001, pp. 295-308. 5) Barnard, J., A new reusability metric for object-oriented software, Software Quality Journal, Vol. 7, pp. 33-50, 1998. 6) Dandashi, F., Rine, D., A Method for Assessing the Reusability of Object- Oriented Code Using a Validated Set of Automated Measurements, in Proc. of the ACM Symposium on Applied Computing (SAC 2002), 2002.

35 35 Questions


Download ppt "Software Quality Improvements from Removing Code Smells Wes J. Lloyd July 15, 2008 Computer Science Department Colorado State University Dr. Sudipto Ghosh,"

Similar presentations


Ads by Google