Successfully reported this slideshow.

Revisiting the Relationship Between Code Smells and Refactoring

1

Share

1 of 12
1 of 12

Revisiting the Relationship Between Code Smells and Refactoring

1

Share

Download to read offline

Slides for the paper "Revisiting the Relationship Between Code Smells and Refactoring" in the Proceedings of the 24th IEEE International Conference on Program Comprehension (ICPC 2016), Austin, TX, USA, May 2016

Slides for the paper "Revisiting the Relationship Between Code Smells and Refactoring" in the Proceedings of the 24th IEEE International Conference on Program Comprehension (ICPC 2016), Austin, TX, USA, May 2016

More Related Content

Related Books

Free with a 14 day trial from Scribd

See all

Related Audiobooks

Free with a 14 day trial from Scribd

See all

Revisiting the Relationship Between Code Smells and Refactoring

  1. 1. REVISITING THE RELATIONSHIP BETWEEN CODE SMELLS AND REFACTORING Norihiro Yoshida (Nagoya Univ.) Tsubasa Saika (Osaka Univ.) Eunjong Choi (NAIST) Ali Ouni (Osaka Univ.) Katsuro Inoue (Osaka Univ.) 1
  2. 2. Code smell and Refactoring Fowler [1] introduced a correspondence relationship between • Smell type • Refactoring to remove its instance Smell type Common Refactoring Feature Envy Extract Method, Move Method, Pull- up Method, Move Field Data Class Move Method, Encapsulate Field, Encapsulate Collection [1] M. Fowler: “Refactoring: Improving the Design of Existing Code”, Addison-Wesley Professional, 1999. 2
  3. 3. Motivation • Bavota et al.’s investigation [2] “40% of the refactorings was performed on classes affected by smells, but just 7% removed the smell.” • It does not align with Fowler’s book. 3 [2] G. Bavota, et al.: “An experimental investigation on the innate relationship between quality and refactoring,” Journal of Systems and Software, 2015. Question Why does refactoring rarely remove code smell?
  4. 4. Applied refactoring patterns rarely correspond to types of the code smell. 4 In order to test the hypothesis, we empirically investigate three OSS projects. An Overview of This Study Hypothesis This study
  5. 5. Data we analyzed - Refactoring instances Refactoring instances in Bavota et al.’s dataset [3] • They manually validated the instances. 5 Period Releases Classes Refactoring instances Xerces-J Oct. ‘99 - Nov. ‘10 34 19,567 6,052 ArgoUML Oct. ‘02 - Dec. ‘11 12 43,686 3,423 Ant Jan. ‘00 - Dec. ‘10 18 22,768 1,493 [3] G. Bavota et al.: “When does a refactoring induce bugs? an empirical study,” In Proc. of SCAM 2012.
  6. 6. Data we analyzed - Code smells 6 Code Smells #Classes BlobClass 692 DataClass 1,679 DistortedHierarchy 8 GodClass 1,294 RefusedParentBequest 538 SchizophrenicClass 311 TraditionBreaker 249 Total 4,771 Code Smells #Methods BlobOperation 4,610 DataClumps 1,402 ExternalDuplication 1,656 FeatureEnvy 1,364 IntensiveCoupling 1,290 InternalDuplication 2,218 MessageChains 31 ShotgunSurgery 65 SiblingDuplication 1,956 Total 14,592 We detected code smells from each release version by inFusion.
  7. 7. List of corresponding refactoring patterns • We made a list of the corresponding refactoring patterns for each type of code smell. • Referred the following books: • M. Fowler: “Refactoring: Improving the Design of Existing Code”, Addison-Wesley Professional, 1999. • M. Lanza and R. Marinescu, “Object-Oriented Metrics in Practice”, Springer-Verlag, 2005. • Investigated the effectiveness of each refactoring pattern for each type of code smell manually. • Once an instance showed the effectiveness, we regarded that the pattern corresponds to the type of code smell. 7
  8. 8. Investigation result - Class-level code smell Code Smells #Refactored Classes #Classes w/ Corresponding Refactorings Ratio BlobClass 210 180 85.7% DataClass 43 8 18.6% DistortedHierarchy 4 0 0.0% GodClass 284 54 19.0% RefusedParentBequest 40 7 17.5% SchizophrenicClass 34 9 26.5% TraditionBreaker 15 3 20.0% Total 630 261 26.8% 8 Only 26.8% were refactored by corresponding patterns. Only BlobClass was frequently refactored by corresponding patterns.
  9. 9. Investigation result - Method-level code smell Code Smells #Refactored method #Methods w/ Corresponding Refactorings Ratio BlobOperation 436 180 68.8% DataClumps 50 8 0.0% ExternalDuplication 69 0 4.3% FeatureEnvy 86 54 10.5% IntensiveCoupling 107 7 22.4% InternalDuplication 164 9 17.1% MessageChains 4 3 0.0% ShotgunSurgery 3 0 0.0% SiblingDuplication 147 31 21.1% Total 1,066 395 16.0% 9 Only 16.0% were refactored by corresponding patterns. Only BlobOperation was frequently refactored by corresponding patterns.
  10. 10. Discussion 10 Applied refactoring patterns rarely correspond to types of the code smell. Hypothesis Only 16.0-26.8% of instances corresponded to types of the code smell. Investigation Result The hypothesis is true!
  11. 11. Conclusion 11 Answer Since corresponding patterns are rarely applied to code smells, refactoring rarely removes them. Question Why does refactoring rarely remove code smell?
  12. 12. Future Work Replicate this study using the following datasets / approaches. • Other datasets of code smells [2] • Other approach to detecting code smells [4] • Other aproach for detecting refactoring instances [5]. 12 [2] G. Bavota, et al.: “An experimental investigation on the innate relationship between quality and refactoring,” Journal of Systems and Software, 2015. [4] F. Palomba, et al.: “Mining version histories for detecting code smells,” IEEE Trans. Softw. Eng., 2015. [5] Z. Xing and E. Stroulia, “Refactoring detection based on UMLDiff change-facts queries,” in Proc. of WCRE 2006.

×