Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

When and Why Your Code Starts to Smell Bad

2,094 views

Published on

In past and recent years, the issues related to man- aging technical debt received significant attention by researchers from both industry and academia. There are several factors that contribute to technical debt. One of these is represented by code bad smells, i.e., symptoms of poor design and implementation choices. While the repercussions of smells on code quality have been empirically assessed, there is still only anecdotal evidence on when and why bad smells are introduced. To fill this gap, we conducted a large empirical study over the change history of 200 open source projects from different software ecosystems and investigated when bad smells are introduced by developers, and the circumstances and reasons behind their introduction. Our study required the development of a strategy to identify smell- introducing commits, the mining of over 0.5M commits, and the manual analysis of 9,164 of them (i.e., those identified as smell- introducing). Our findings mostly contradict common wisdom stating that smells are being introduced during evolutionary tasks. In the light of our results, we also call for the need to develop a new generation of recommendation systems aimed at properly planning smell refactoring activities.

Published in: Software
  • Increasing Sex Drive And Getting Harder Erections, Naturally ●●● https://tinyurl.com/yy3nfggr
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here

When and Why Your Code Starts to Smell Bad

  1. 1. When and WhyYour Code Starts to Smell Bad
  2. 2. A BRIEF HISTORY OF CODE SMELLS Ouverture When and WhyYour Code Starts to Smell Bad
  3. 3. Bad Code Smells “Bad Code Smells are symptoms of poor design or implementation choices” [Martin Fowler]
  4. 4. Negative Impact of Bad Smells [Abbes et al. CSMR 2011] Bad Smells hinder code comprehensibility
  5. 5. [Khomh et al. EMSE 2012] Bad Smells increase change- and fault-proneness Negative Impact of Bad Smells
  6. 6. [Banker et al. Communications of the ACM] Bad Smells increase maintenance costs Negative Impact of Bad Smells
  7. 7. Studies tried explaining their lifespan [Peters and Zaidman - CSMR 2012] Developers are aware of code smells, but not very concerned about their impact
  8. 8. and longevity… [Arcoverde et al. - IWRT 2011] Developers deliberately postpone refactorings for different reasons
  9. 9. Bad Smells DetectionTechniques [Moha et al. -TSE 2010] DECOR [Palomba et al. -TSE 2015] HIST[Marinescu - ICSM 2004] Detection Strategies
  10. 10. [Tsantalis et al. -TSE 2009] JDeodorant [Bavota et al. -TSE 2014] [Bavota et al. -TOSEM 2014] Methodbook R3 Bad Smells RefactoringTechniques
  11. 11. however…
  12. 12. Are we missing anything?
  13. 13. 1999 2000 2003 2007 WHEN AND WHY YOUR CODE TO SMELL BAD STARTS Michele Tufano, Fabio Palomba, Gabriele Bavota, Rocco Oliveto, Massimiliano Di Penta,Andrea De Lucia, Denys Poshyvanyk 2010 ? CLASS NTRODUCTION IM NEW FEATURE SMELL INTRODUCTION MAIN OPERATION MAINTENANCE OPERATION
  14. 14. 5smells considered from the catalogues by Fowler and Brown Blob Class Data Should Be Private Complex Class Functional Decomposition Spaghetti Code Study Design
  15. 15. 3different ecosystems analyzed Study Design
  16. 16. 200 Study Design total analyzed systems
  17. 17. ?When are code smells introduced RQ1 1999 2000 2003 2007 2010 CLASS NTRODUCTION IM NEW FEATURE SMELL INTRODUCTION MAIN OPERATION MAINTENANCE OPERATION
  18. 18. WHEN are code smells introduced Data Extraction History Miner DECOR c1 c2 … cn-1 cn smells(c1)
  19. 19. History Miner DECOR c1 c2 … cn-1 cn smells(c2) DECOR WHEN are code smells introduced Data Extraction
  20. 20. History Miner DECOR c1 c2 … cn-1 cn smells(cn-1) DECOR DECOR WHEN are code smells introduced Data Extraction
  21. 21. History Miner DECOR c1 c2 … cn-1 cn smells(cn) DECOR DECOR DECOR WHEN are code smells introduced Data Extraction
  22. 22. History Miner DECOR c1 c2 … cn-1 cn smells(cn) DECOR DECOR DECOR 579,671 commits analyzed 8 weeks of computation WHEN are code smells introduced Data Extraction
  23. 23. c1 c2 c3 c4 c5 c6 c7 c8 c9 c10 c11 Class Ci CREATED Class Ci SMELL … Ci For each file detected as smelly, we count the number of commits between its introduction in the system and the commit in which DECOR detect a smell WHEN are code smells introduced Data Extraction
  24. 24. c1 c2 c3 Class Ci CREATED SMELL Smell introduced during the creation of the artifact Two possible scenarios WHEN are code smells introduced Data Extraction
  25. 25. c1 c2 c3 Class Ci CREATED SMELL Smell introduced after several maintenance activities Two possible scenarios c1 c2 … ck cn… … Ci Class Ci CREATED Class Ci SMELL WHEN are code smells introduced Data Extraction
  26. 26. Smell introduced after several maintenance activities c c … c c… … Class C CREATED Class C SMELL LOC WMC NOA CBO RFCLCOM NOM WHEN are code smells introduced Data Extraction
  27. 27. Smell introduced after several maintenance activities c c … c c… … Class C CREATED Class C SMELL LOC WMC NOA CBO RFCLCOM NOM We want to understand whether the trend followed by such metrics differ between files affected by a specific type of smell and files not affected by such a smell. WHEN are code smells introduced Data Extraction
  28. 28. 100 200 300 400 500 100 200 300 400 500 100 200 300 400 500 Logarithmic function Exponential function Sine/Cosine function 100 200 300 400 500 Linear function WHEN are code smells introduced Data Extraction
  29. 29. 100 200 300 400 500 100 200 300 400 500 Logarithmic function 100 200 300 400 500 Sine/Cosine function 100 200 300 400 500 Linear function Exponential function We experienced that the best approximation function is the linear one WHEN are code smells introduced Data Extraction
  30. 30. SMELLY FILES 100 200 300 400 500 WHEN are code smells introduced Data Extraction
  31. 31. NON SMELLY 
FILES SMELLY FILES 100 200 300 400 500 10 20 30 40 50 WHEN are code smells introduced Data Extraction
  32. 32. NON SMELLY 
FILES SMELLY FILES 100 200 300 400 500 10 20 30 40 50 We compared the two distributions using the two-tailed Mann Whitney UTest WHEN are code smells introduced Data Extraction
  33. 33. NOT SMELLY 
FILES SMELLY FILES 100 200 300 400 500 10 20 30 40 50 We compared the two distributions using the two-tailed Mann Whitney UTest We estimated the magnitude of the observed differences using the Cliff’s Delta WHEN are code smells introduced Data Extraction
  34. 34. ?When are code smells introduced Results 1999 2000 2003 2007 2010 CLASS NTRODUCTION IM NEW FEATURE SMELL INTRODUCTION MAIN OPERATION MAINTENANCE OPERATION
  35. 35. Commits required to a class for becoming smell WHEN blobs are introduced 50 1000 25 75 Generally, blobs affect a class since its creation
  36. 36. Commits required to a class for becoming smell 50 1000 25 75 Generally, blobs affect a class since its creation There are several cases in which a blob is introduced during maintenance activities WHEN blobs are introduced
  37. 37. smelly not smelly LOC slope of smelly classes is 295 times higher with respect to non-smelly classes Cliff’s Delta: Large Statistically Significant WHEN blobs are introduced
  38. 38. WHEN blobs are introduced smelly not smelly LCOM slope of smelly classes is 3399.6 times higher with respect to non-smelly classes Cliff’s Delta: Large Statistically Significant
  39. 39. WMC RFC CBO NOM NOA 16,26 20,17 1,15 6,81 2,15 Results are confirmed for other metrics WHEN blobs are introduced
  40. 40. WHEN functional decompositions are introduced Commits required to a class for becoming smell 50 1000 25 75 Also functional decompositions are mainly introduced at “artifact creation time”
  41. 41. Commits required to a class for becoming smell 50 1000 25 75 Also functional decompositions are mainly introduced at “artifact creation time” Several instances are the consequence of maintenance operations WHEN functional decompositions are introduced
  42. 42. smelly not smelly LOC slope of smelly classes is 49 times lower with respect to non-smelly classes Cliff’s Delta: Large Statistically Significant WHEN functional decompositions are introduced
  43. 43. ? WHEN functional decompositions are introduced LOC slope of smelly classes is 49 times lower with respect to non-smelly classes
  44. 44. ?“A class where inheritance and polymorphism are poorly used, declaring many private fields and implementing few methods” WHEN functional decompositions are introduced LOC slope of smelly classes is 49 times lower with respect to non-smelly classes
  45. 45. WMC RFC CBO NOM NOA -5,59 1,15 -2,60 2,15 Results are confirmed for other metrics -5,67 -4,50 -0,19 -0,40 WHEN functional decompositions are introduced
  46. 46. ?Why are code smells introduced RQ2 1999 2000 2003 2007 2010 CLASS NTRODUCTION IM NEW FEATURE SMELL INTRODUCTION MAIN OPERATION MAINTENANCE OPERATION
  47. 47. WHY are code smells introduced Data Extraction Our goal is to understand under which situations developers tend to introduce smells
  48. 48. WHY are code smells introduced Data Extraction Our goal is to understand under which situations developers tend to introduce smells Tagging of commits that introduce a smell
  49. 49. WHY are code smells introduced Data Extraction Our goal is to understand under which situations developers tend to introduce smells “First pass at implementing the feature of being able to specify additional goals that can be run after the creation of a project from an archetype“ EHNANCEMENT Tagging of commits that introduce a smell
  50. 50. WHY are code smells introduced Data Extraction How to know which are the commits that introduce a smell?
  51. 51. SMELLY FILES 100 200 300 400 500 WHY are code smells introduced Data Extraction c1 c2 c3 c4 c5 c6 c7 c8 LOC
  52. 52. SMELLY FILES 100 200 300 400 500 WHY are code smells introduced Data Extraction c1 c2 c3 c4 c5 c6 c7 c8 LOC Commits c3, c5 and c7 are smell-introducing commits
  53. 53. WHY are code smells introduced Data Extraction 9,164 smell-inducing commits
  54. 54. WHY are code smells introduced Data Extraction Commit GoalTag Enhancement Bug Fixing New Feature Refactoring 9,164 smell-inducing commits
  55. 55. WHY are code smells introduced Data Extraction Commit GoalTag Project StatusTag Enhancement Bug Fixing New Feature Refactoring Project Start-Up Working on Release 9,164 smell-inducing commits
  56. 56. WHY are code smells introduced Data Extraction Commit GoalTag Developer StatusTag Enhancement Bug Fixing New Feature Refactoring Workload Ownership Newcomer 9,164 smell-inducing commits Project StatusTag Project Start-Up Working on Release
  57. 57. ?Why are code smells introduced Results 1999 2000 2003 2007 2010 CLASS NTRODUCTION IM NEW FEATURE SMELL INTRODUCTION MAIN OPERATION MAINTENANCE OPERATION
  58. 58. WHY are code smells introduced Commit GoalTag BLOB CDSBP CC FD SC BF E NF R Blob Class Data Should Be Private Complex Class Functional Decomposition Spaghetti Code Bug Fixing 0 1005025 75 Enhancement New Feature Refactoring
  59. 59. WHY are code smells introduced BLOB CDSBP CC FD SC Day Week Monh More 0 1005025 75 Working on ReleaseTag One Day One Month More One Week Blob Class Data Should Be Private Complex Class Functional Decomposition Spaghetti Code
  60. 60. WHY are code smells introduced BLOB CDSBP CC FD SC Day Week Month More 0 1005025 75 Project StartupTag One Week OneYear More One Month Blob Class Data Should Be Private Complex Class Functional Decomposition Spaghetti Code
  61. 61. WHY are code smells introduced BLOB CDSBP CC FD SC Low Medium High 0 1005025 75 WorkloadTag High Low Medium Blob Class Data Should Be Private Complex Class Functional Decomposition Spaghetti Code
  62. 62. WHY are code smells introduced 0 1005025 75 OwnershipTag BLOB CDSBP CC FD SC True FalseTrue False Blob Class Data Should Be Private Complex Class Functional Decomposition Spaghetti Code
  63. 63. WHY are code smells introduced 0 1005025 75 NewcomerTag BLOB CDSBP CC FD SC True FalseTrue False Blob Class Data Should Be Private Complex Class Functional Decomposition Spaghetti Code
  64. 64. 1999 2000 2003 2007 WHEN AND WHY YOUR CODE TO SMELL BAD STARTS Michele Tufano, Fabio Palomba, Gabriele Bavota, Rocco Oliveto, Massimiliano Di Penta,Andrea De Lucia, Denys Poshyvanyk 2010 ? CLASS NTRODUCTION IM NEW FEATURE SMELL INTRODUCTION MAIN OPERATION MAINTENANCE OPERATION Epilogue
  65. 65. Lesson I The artifacts are often affected by bad smells since their creation
  66. 66. The artifacts are often affected by bad smells since their creation Lesson I Classes becoming smells have peculiarmetrics trends Lesson II
  67. 67. Lesson I Lesson II Goal: Enhancement or New Features… but also refactoring! Lesson III The artifacts are often affected by bad smells since their creation Classes becoming smells have peculiarmetrics trends
  68. 68. Lesson I Lesson II Goal: Enhancement or New Features… but also refactoring! Lesson III Developers with high workload and time pressure tend to introduce smellinstances Lesson IV The artifacts are often affected by bad smells since their creation Classes becoming smells have peculiarmetrics trends
  69. 69. Lesson I Lesson II Goal: Enhancement or New Features… but also refactoring! Lesson III Developers with high workload and time pressure tend to introduce smellinstances Lesson IV The artifacts are often affected by bad smells since their creation Classes becoming smells have peculiarmetrics trends ?
  70. 70. Additional Slides for questions
  71. 71. 50 100 0 25 75 LOC LCOM WMC RFC CBO NOM NOA Smelly Not Smelly Smelly Not Smelly Smelly Not Smelly Smelly Not Smelly Smelly Not Smelly Smelly Not Smelly Smelly Not Smelly 73.76 0.25 849.9 0.25 16.26 0.07 20.17 0.06 1.15 0.09 6.81 0.02 2.15 0.02 Large Large Large Large Small Large Medium SLOPE CLIFF’S DELTA CMPCommits required for becoming smell WHEN blobs are introduced
  72. 72. 50 100 0 25 75 Commits required for becoming smell LOC LCOM WMC RFC CBO NOM NOA Smelly Not Smelly Smelly Not Smelly Smelly Not Smelly Smelly Not Smelly Smelly Not Smelly Smelly Not Smelly Smelly Not Smelly 9.36 0.26 290.5 0.43 1.39 0.07 0.57 0.06 0.44 0.11 0.94 0.03 3.42 0.02 Large Negligible Negligible Negligible Small Negligible Large SLOPE CLIFF’S DELTA CMP WHEN class data should be private are introduced
  73. 73. LOC LCOM WMC RFC CBO NOM NOA Smelly Not Smelly Smelly Not Smelly Smelly Not Smelly Smelly Not Smelly Smelly Not Smelly Smelly Not Smelly Smelly Not Smelly 63.0 0.21 1573.0 0.34 19.36 0.07 15.68 0.04 1.25 0.10 9.29 0.02 1.88 0.03 Large Large Large Large Small Large Medium SLOPE CLIFF’S DELTA CMP WHEN complex classes are introduced 50 100 0 25 75 Commits required for becoming smell
  74. 74. LOC LCOM WMC RFC CBO NOM NOA Smelly Not Smelly Smelly Not Smelly Smelly Not Smelly Smelly Not Smelly Smelly Not Smelly Smelly Not Smelly Smelly Not Smelly -14.09 0.29 -5.59 0.75 -5.67 0.08 -4.50 0.07 -0.19 0.12 -2.60 0.03 -0.40 0.02 Large Large Large Large Negligible Large Small SLOPE CLIFF’S DELTA CMP WHEN functional decompositions are introduced 50 100 0 25 75 Commits required for becoming smell
  75. 75. LOC LCOM WMC RFC CBO NOM NOA Smelly Not Smelly Smelly Not Smelly Smelly Not Smelly Smelly Not Smelly Smelly Not Smelly Smelly Not Smelly Smelly Not Smelly 134.0 0.17 597.0 1.02 15.09 0.04 9.36 -0.02 1.27 0.15 5.84 0.01 7.80 0.03 Large Large Large Large Negligible Large Large SLOPE CLIFF’S DELTA CMP WHEN spaghetti codes are introduced 50 100 0 25 75 Commits required for becoming smell

×