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

Slides:



Advertisements
Similar presentations
Bartłomiej Bodziechowski 1, Eryk Ciepiela 2, Marian Bubak 1,2 1 AGH University of Science and Technology, Department of Computer Science AGH, 2 AGH University.
Advertisements

Metrics for OO Design Distinct & measurable characteristics of OO design:- Size:-it is defined as – population,volume,length & functionality Population.
Presentation of the Quantitative Software Engineering (QuaSE) Lab, University of Alberta Giancarlo Succi Department of Electrical and Computer Engineering.
Min Zhang School of Computer Science University of Hertfordshire
1 ECE 453 – CS 447 – SE 465 Software Testing & Quality Assurance Case Studies Instructor Paulo Alencar.
Prediction of fault-proneness at early phase in object-oriented development Toshihiro Kamiya †, Shinji Kusumoto † and Katsuro Inoue †‡ † Osaka University.
Figures – Chapter 24.
OORPT Object-Oriented Reengineering Patterns and Techniques 7. Problem Detection Prof. O. Nierstrasz.
Software Construction and Evolution - CSSE 375 Bad Smells in Code Shawn Bohner & Steve Chenoweth.
Page 1 Building Reliable Component-based Systems Chapter 7 - Role-Based Component Engineering Chapter 7 Role-Based Component Engineering.
Investigating JAVA Classes with Formal Concept Analysis Uri Dekel Based on M.Sc. work at the Israeli Institute of Technology. To appear:
Software engineering for real-time systems
Software Quality Metrics
© S. Demeyer, S. Ducasse, O. Nierstrasz Duplication.1 7. Problem Detection Metrics  Software quality  Analyzing trends Duplicated Code  Detection techniques.
Soft. Eng. II, Spr. 02Dr Driss Kettani, from I. Sommerville1 CSC-3325: Chapter 6 Title : The Software Quality Reading: I. Sommerville, Chap: 24.
Object-Oriented Metrics
An Approach to Measure Java Code Quality in Reuse Environment Aline Timóteo Advisor: Silvio Meira Co-advisor: Eduardo Almeida UFPE.
1 An exploratory investigation on the Invasiveness of Environmental Modeling Frameworks 18 th IMACS World Congress, MODSIM09 Cairns, Australia July 2009.
University of Toronto Department of Computer Science © 2001, Steve Easterbrook CSC444 Lec22 1 Lecture 22: Software Measurement Basics of software measurement.
Chidamber & Kemerer Suite of Metrics
“Enhancing Reuse with Information Hiding” ITT Proceedings of the Workshop on Reusability in Programming, 1983 Reprinted in Software Reusability, Volume.
Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University 1 Refactoring.
Chapter 6 : Software Metrics
Paradigm Independent Software Complexity Metrics Dr. Zoltán Porkoláb Department of Programming Languages and Compilers Eötvös Loránd University, Faculty.
An Approach to Measure Java Code Quality in Reuse Environment Aline Timóteo Advisor: Silvio Meira UFPE – Federal University of Pernambuco
Product Metrics An overview. What are metrics? “ A quantitative measure of the degree to which a system, component, or process possesses a given attribute.”
1 OO Metrics-Sept2001 Principal Components of Orthogonal Object-Oriented Metrics Victor Laing SRS Information Services Software Assurance Technology Center.
On the Modularity Assessment of Aspect- Oriented Multi-Agent Systems Product Lines: a Quantitative Study Camila Nunes
The CK Metrics Suite. Weighted Methods Per Class b To use this metric, the software engineer must repeat this process n times, where n is the number of.
Lecture 4 Software Metrics
Software Engineering Research Group, Graduate School of Engineering Science, Osaka University 1 Evaluation of a Business Application Framework Using Complexity.
R2PL, Pittsburgh November 10, 2005 Copyright © Fraunhofer IESE 2005 Identifying Domain-Specific Reusable Components from Existing OO Systems to Support.
1 These courseware materials are to be used in conjunction with Software Engineering: A Practitioner’s Approach, 5/e and are provided with permission by.
Software Quality Improvements from Refactoring Wes J. Lloyd July 15, 2008 Computer Science Department Colorado State University Dr. Sudipto Ghosh, co-advisor.
1 Object-Oriented Design in Practice. Could/Should We Do Better? Dr. Radu Marinescu Timişoara, Object-Oriented Design in Practice. Could/Should.
1 Metrics and lessons learned for OO projects Kan Ch 12 Steve Chenoweth, RHIT Above – New chapter, same Halstead. He also predicted various other project.
An Automatic Software Quality Measurement System.
SOFTWARE METRICS. Software Process Revisited The Software Process has a common process framework containing: u framework activities - for all software.
Software Engineering CS3003 Lecture 4 Code bad smells and refactoring.
An Approach to Measure Java Code Quality in Reuse Environment Master: Aline Timóteo Professor: Silvio Meira UFPE – Federal University.
CSc 461/561 Information Systems Engineering Lecture 5 – Software Metrics.
Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University IWPSE 2003 Program.
Measurement and quality assessment Framework for product metrics – Measure, measurement, and metrics – Formulation, collection, analysis, interpretation,
Chapter 5: Software Re-Engineering Omar Meqdadi SE 3860 Lecture 5 Department of Computer Science and Software Engineering University of Wisconsin-Platteville.
Advanced Software Engineering Lecture 4: Process & Project Metrics.
Survey of Tools to Support Safe Adaptation with Validation Alain Esteva-Ramirez School of Computing and Information Sciences Florida International University.
Diagnosing Design Problems in Object Oriented Systems Adrian Trifu, Radu Marinescu Proceedings of the 12th IEEE Working Conference on Reverse Engineering.
Ontology Support for Abstraction Layer Modularization Hyun Cho, Jeff Gray Department of Computer Science University of Alabama
Pertemuan 12 Refactoring Mata kuliah: T0144 – Advanced Topics in Software Engineering Tahun: 2010.
1 Predicting Classes in Need of Refactoring – An Application of Static Metrics Liming Zhao Jane Hayes 23 September 2006.
An Approach to Measure Java Code Quality in Reuse Environment Author: Aline Timóteo Professor: Silvio Meira UFPE – Federal University.
Presented by Lu Xiao Drexel University Quantifying Architectural Debt.
Architecting Complexity HOW UNDERSTANDING COMPLEXITY PROMOTES SIMPLICITY.
A Hierarchical Model for Object-Oriented Design Quality Assessment
Assessment of Geant4 Software Quality
Course Notes Set 12: Object-Oriented Metrics
Design Characteristics and Metrics
Towards a Multi-paradigm Complexity Measure
Do Developers Focus on Severe Code Smells?
Object-Oriented Metrics
Design Metrics Software Engineering Fall 2003
A Pluggable Tool for Measuring Software Metrics from Source Code
Design Metrics Software Engineering Fall 2003
Software Metrics Validation using Version control
Software Metrics “How do we measure the software?”
Chapter 13 Quality Management
Refactoring.
Software Metrics SAD ::: Fall 2015 Sabbir Muhammad Saleh.
Refactoring.
Chapter 8: Design: Characteristics and Metrics
Presentation transcript:

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 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 Evapotranspiration Harmon equation Penman-Monteith equation Blaney-Criddle equation Makkink equation Hargreaves formula eddy covariance technique Potential evapotranspiration (PET)

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 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 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 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 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 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 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 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 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 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 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 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, NCSS 668 classes, 3088 methods, NCSS

16 Static Analysis Tools JavaNCSS JavaNCSS Checkstyle Checkstyle Checkstyle Simian plugin Checkstyle Simian plugin JHawk JHawk CKJM CKJM

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 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 Smell Detection Lazy Classes Duplicate Code Long Methods 2631 Large Classes Long Parameter List ACRU2000CEAP/J2000PRMSSmell

20 ACRU Lazy Classes ACRU – –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 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 Lazy Class Refactoring line classes removed line classes removed line classes removed line classes removed line classes removed line classes removed Original Code StatementsMethodsClasses Removed # ClassesRefactoring

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 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 Coupling (CBO)‏ line classes removed line classes removed line classes removed line classes removed line classes removed line classes removed Original Code Average CBO w/o lazy classes Average CBO all classes Refactoring

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

27 Lack of Cohesion (LCOM)‏ line classes removed line classes removed line classes removed line classes removed line classes removed line classes removed Original Code Average LCOM w/o lazy classes Average LCOM all classes Refactoring

28 Total Cyclomatic Complexity (TCC)‏ line classes removed line classes removed line classes removed line classes removed line classes removed line classes removed Original Code Average TCC w/o lazy classes Average TCC all classes Refactoring

29 Response for a class (RFC)‏ line classes removed line classes removed line classes removed line classes removed line classes removed line classes removed Original Code Average RFC w/o lazy classes Average RFC all classes Refactoring

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 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 Questions

33 References 1) Chidamber, S., Kemerer, C., A metrics suite for object oriented design. IEEE Transactions on Software Engineering, 20(6); , ) Fowler, M., et al., Refactoring: Improving the Design of Existing Code: Addison-Wesley, ) Emden, E., Moonen, L., Java Quality Assurance by Detecting Code Smells, in Proc. of the 9th Working Conference on Reverse Engineering (WCRE '02), , ) 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: , ) 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, ) 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 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, ) Mantyla, M., Vanhanen, J., Lassenius, C., in Proc. 20th IEEE International Conference on Software Maintenance (ICSM '04), “Bad Smells – Humans as Code Critics”, , ) 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), ) 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 ) Barnard, J., A new reusability metric for object-oriented software, Software Quality Journal, Vol. 7, pp , ) 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 Questions