Presentation is loading. Please wait.

Presentation is loading. Please wait.

Investigating the Evolution of Bad Smells in Object-Oriented Code Alexander Chatzigeorgiou Anastasios Manakos University of Macedonia Thessaloniki, Greece.

Similar presentations


Presentation on theme: "Investigating the Evolution of Bad Smells in Object-Oriented Code Alexander Chatzigeorgiou Anastasios Manakos University of Macedonia Thessaloniki, Greece."— Presentation transcript:

1 Investigating the Evolution of Bad Smells in Object-Oriented Code Alexander Chatzigeorgiou Anastasios Manakos University of Macedonia Thessaloniki, Greece 7th Int. Conference on the Quality of Information and Communications Technology (QUATIC’ 2010)

2 Design Problems non-compliance with design principles excessive metric values lack of design patterns violations of design heuristics Fowler’s bad smells

3 Software Ageing Design quality decays well-designed code

4 Goal To employ past source code data in order to investigate the evolution of design problems Focus is on the problems rather than the refactorings Shed light on questions such as: Does the number of problems increase over time ? Are problems solved only after targeted activities ? Do smells appear during software evolution ? How frequent are refactoring activities ? How urgent is it to remove the identified smells ?

5 Context Two open source projects: JFlex (10 versions) JFreeChart (14 versions) Detection tool: JDeodorant Identified smells: Long Method Feature Envy State Checking

6 Long Method int i; int product = 1; for(i = 0; i < N; ++i) { product = product *i; } System.out.println(product); Pieces of code with large size, high complexity and low cohesion int i; int sum = 0; for(i = 0; i < N; ++i) { sum = sum + i; } System.out.println(sum);

7 Feature Envy A method is “more interested in a class other than the one it actually is in” m(Target t) { t.m1(); t.m2(); t.m3(); } m() { m1(); m2(); m3(); }

8 State Checking State Checking manifests itself as conditional statements that select an execution path based on the state of an object doStateA(); switch(type) { case STATE_A: break; case STATE_B: break; } doStateB();

9 Total Number of Smells

10 Long Method JFlex

11 Elimination of smells: Reasons Code Rewriting → Accidental Elimination Code Removal → Unintentional Elimination Class/Method Removal → Unintentional Elimination Intentional Refactoring Activity: Long Method: Extract method refactoring has been applied Feature Envy: Suffering method is moved to the target class State Checking: Polymorphism has been introduced

12 Categories Α Β1Β1 Β2Β2 C1C1 C2C2 D1D1 D2D2 D3D3 D4D4 Method is introduced Smell appears

13 Results JFlex Long Method -90% extend up to the latest version -10% disappear during the course of the project -3.33% smell removal - no case can be regarded as application of refactoring

14 Results JFreeChart Long Method ~79% extend up to the latest version ~60% exist from the beginning → design problems are also a consequence of inefficient OOAD -7.24% explicit smell removal - only three cases of unambiguous Extract Method

15 Results Smell Categories JFlexJFreeChart Long Method Feature Envy State Checking Long Method Feature Envy State Checking A 52 57.77% 8 36.36% 3 60.0% 21 4.58% 7 14.0% B 1 17 18.88% 3 13.63% 1 20.0% 124 27.07% 5 21.73% 5 10.0% B 2 12 13.33% 5 22.72% 1 20.0% 216 47.16% 3 13.04% 23 46.0% C 1 2 2.22% 5 22.72% 6 1.31% 3 6.0% C 2 6 6.66% 1 4.54% 18 3.93% 1 4.34% 5 10.0% D 1 38 8.29% 1 4.34% 6 12.0% D 2 9 1.96% 2 8.69% D 3 1 1.11% 19 4.14% 11 47.82% 1 2.0% D 4 7 1.52% Total Number of Distinct Smell Cases 902254582350 ~75% ~15% ~40%

16 Average Time of Persistence A value of 100% would indicate that the smell exists throughout all examined versions JFlexJFreeChart Long Method Feature Envy State Checking Long Method Feature Envy State Checking 77%68% 40%28%57% some smells are more common and have longer persistence → warrant more attention

17 Unambiguously Identified Refactorings Out of 648 cases, only in 5 a refactoring activity was undertaken to remove the smell JFlexJFreeChart Long Method Feature Envy State Checking Long Method Feature Envy State Checking 0 (0.00%) 1 (4.54%) 0 (0.00%) 3 (0.65%) 1 (4.34%) 0 (0.00%) Possible Reasons: Designers perform refactoring based on subjective perception Limited support by CASE tools to identify non-trivial smells

18 Active Bad Smells Are all identified design problems important ? Example: Why would it be urgent to improve a method suffering from Long Method if the method had never been changed? Need to define (quantify) the urgency to resolve a problem One possible source of information: Past code versions Underlying Assumption: Code fragments that have been subject to maintenance in that past are more likely to undergo changes Active Bad Smell: A design problem where the affected code has been the subject of maintenance, at least once.

19 What to look for Long Method: its presence implies that it might be difficult to maintain the method → perform refactoring if we expect that the method will change Previous versions: detect changes in the implementation of the method change

20 What to look for Feature Envy: is related to the access of foreign members → perform refactoring if we expect that the total number of accesses to foreign members will change Previous versions: detect changes in the number of accesses to foreign members

21 What to look for State Checking: implies a missed opportunity for polymorphism if (state == StateA) {... } else if (state == StateB) {... } else if (state == StateC) {... } +... + (additional statements)...

22 Results JFreeChart State Checking

23 Results – Percentage of Active Smells Significantly smaller number of smells is alarming JFlexJFreeChart Long Method Feature Envy State Checking Long Method Feature Envy State Checking 53 58.89% 6 27.27% 1 20% 285 62.23% 0 0% 26 52% Long Method Larger percentage of active smells Larger total number Longer persistence → maintenance effort should prioritize them

24 Conclusions Source code history tells us: 1.Design problems accumulate as projects mature 2.A significant percentage of problems are present from the beginning 3.Very few smells are removed due to refactorings 4.Refactoring identification and suggestion can be made more accurate and meaningful Compare the evolution of smells with the results of tools that identify applied refactorings

25 Thank you for your attention 7th Int. Conference on the Quality of Information and Communications Technology (QUATIC’ 2010)


Download ppt "Investigating the Evolution of Bad Smells in Object-Oriented Code Alexander Chatzigeorgiou Anastasios Manakos University of Macedonia Thessaloniki, Greece."

Similar presentations


Ads by Google