An Exploratory Study of Code Smells in Evolving Aspect-Oriented Systems Isela Macia Alessandro...

24
An Exploratory Study of Code Smells in Evolving Aspect-Oriented Systems Isela Macia Alessandro Garcia Arndt von Staa

description

Study Settings 9/2/20163 Nome do Autor © LES/PUC-Rio Target Systems iBATISHWMM ApplicationFrameworkWeb-basedProduct-Line #/Selected Releases4/410/108/3 KLOC # of Aspects Target SystemsAspects HWConcurrency, EH, Distribution, Persistence, and 5 Patterns MM13 Product-Line Features iBATISConcurrency, EH, Type Mapping, Connection, Transaction, Error Context, and 4 Patterns

Transcript of An Exploratory Study of Code Smells in Evolving Aspect-Oriented Systems Isela Macia Alessandro...

Page 1: An Exploratory Study of Code Smells in Evolving Aspect-Oriented Systems Isela Macia Alessandro Garcia Arndt von Staa.

An Exploratory Study of Code Smells inEvolving Aspect-Oriented Systems

Isela MaciaAlessandro Garcia

Arndt von Staa

Page 2: An Exploratory Study of Code Smells in Evolving Aspect-Oriented Systems Isela Macia Alessandro Garcia Arndt von Staa.

Motivation

03/05/23 2Nome do Autor © LES/PUC-Rio

• Aspect-oriented programming (AOP) aims at improving the separation of concerns that crosscut multiple modules

• However, the inadequate use of AOP mechanisms can lead to code smells (or anomalies)

• There is no systematic investigation on how often these anomalies can occur in practice

• There is also little knowledge about their harmful impact on software maintenance

Page 3: An Exploratory Study of Code Smells in Evolving Aspect-Oriented Systems Isela Macia Alessandro Garcia Arndt von Staa.

Study Settings

03/05/23 3Nome do Autor © LES/PUC-Rio

• Target Systems

iBATIS HW MM

Application Framework Web-based Product-Line

#/Selected Releases 4/4 10/10 8/3

KLOC 45 60 27

# of Aspects 179 195 59

Target Systems AspectsHW Concurrency, EH, Distribution, Persistence, and 5 Patterns

MM 13 Product-Line Features

iBATIS Concurrency, EH, Type Mapping, Connection, Transaction, Error Context, and 4 Patterns

Page 4: An Exploratory Study of Code Smells in Evolving Aspect-Oriented Systems Isela Macia Alessandro Garcia Arndt von Staa.

Study Phases and Assessment Procedures

• Selection of previous-documented code smells– Piveta et al, Srivist e Mauncheransi

• Identification of Code Smells

• Discovery of New Code Smells

• Analysis of Code Smell Behavior

03/05/23 4Nome do Autor © LES/PUC-Rio

Page 5: An Exploratory Study of Code Smells in Evolving Aspect-Oriented Systems Isela Macia Alessandro Garcia Arndt von Staa.

An Overview of Found Code Smells

Category Code Smell Ocurred Documented

Anomalous Pointcut Definition

Redudant Pointcut (RP) Yes No

Idle Pointcut (IdP) Yes No

God Pointcut (GP) Yes No

Duplicate Pointcut (DP) Yes Yes

Anonymous Pointcut (AP) Yes Yes

Borrowed Pointcut (BP) No Yes

Aspect Definitions

Lazy Aspect (LP) Yes Yes

Abstract Method Definition (AMI) No Yes

Various Concerns (VC) No Yes

Undesirable Definitions

God Aspect (GA) Yes No

Composition Bloat (CB) Yes No

Feature Envy (FE) No Yes

Forced Join Point (FJP) Yes No

03/05/23 5Nome do Autor © LES/PUC-Rio

Page 6: An Exploratory Study of Code Smells in Evolving Aspect-Oriented Systems Isela Macia Alessandro Garcia Arndt von Staa.

Revealing New Code Smells

03/05/23 6Nome do Autor © LES/PUC-Rio

• Idle Pointcut is associated with pointcuts, which do not match any join point. Idle Pointcut is a case of code smell that was created to address limitations in the definition of existing code smells: Junk Material

//aspect codepublic aspect SqlmapEngineMappingECAspect{ ... public pointcut callSqlExecuteUpdate(): call(protected int sqlExecuteUpdate(..)) && withincode(public int GeneralStatement.executeUpdate(..)) || withincode( protected List GeneralStatement.executeQueryWithCallback(..)));}

//base codepublic class GeneralStatement extends BaseStatement{ ... public int executeUpdate()throws SQLException{ rows = executeUpdatePartOne(..); }}

Page 7: An Exploratory Study of Code Smells in Evolving Aspect-Oriented Systems Isela Macia Alessandro Garcia Arndt von Staa.

Revealing New Code Smells

• Redundant Pointcut code smell is associated with (partial or full) pointcut expressions equivalent to others that have already been defined. This code smell can be characterized as a variation of Duplicate Pointcut.

03/05/23 7Nome do Autor © LES/PUC-Rio

public aspect AnimalComplaintStateAspect { … after(..): initialization(AnimalComplaint+.new(..)) && target(animalComplaint) { … }

after(..): initialization(AnimalComplaint+.new(..)) && target(animalComplaint) && args(…) { … } }

Page 8: An Exploratory Study of Code Smells in Evolving Aspect-Oriented Systems Isela Macia Alessandro Garcia Arndt von Staa.

Revealing New Code Smells

• Forced Join Point is associated with members (attributes or methods) in the base code that are only exposed to be used by aspects

03/05/23 8Nome do Autor © LES/PUC-Rio

//aspect codepublic aspect commomBeansEHAspect { ... before(..) : (execution( void HWServlet.doPost(..)) || execution (void HWServlet.doGet(..))) && args(..) && within(..) { ... }}

// base codepublic class HWServlet extends HttpServlet { ... public void doPost(...) throws ServletException and IOException {} public void doGet(..) throws ServletException, IOException {} }}

Page 9: An Exploratory Study of Code Smells in Evolving Aspect-Oriented Systems Isela Macia Alessandro Garcia Arndt von Staa.

Revealing New Code Smells

• Composition Bloat is a complex base computation that is advised by multiple aspects.

03/05/23 10Nome do Autor © LES/PUC-Rio

public aspect PhotoAndMusicAndVideo{ pointcut startApp(MainUIMidlet mdlt): execution (public void MainUIMidlet.startpp()) && this(midlet); after (MainUIMidlet mdlt): startApp(mdlt) { BaseController imgCtr = mdlt.imageRootController; AlbumData imgModel = mdlt.imageModel; BaseController mCtr= mdlt.musicRootController; AlbumData musicModel = mdlt.musicModel; BaseController vCtr= mdlt.videoRootController; AlbumData videoModel = mdlt.videoModel; selectcontroller.setNextController(imgCtr); selectcontroller.setMusicAlbumData(musicModel); selectcontroller.setVideoController(vCtr); … } }

Page 10: An Exploratory Study of Code Smells in Evolving Aspect-Oriented Systems Isela Macia Alessandro Garcia Arndt von Staa.

Frequency of Code Smells is Manifold

• The variation of smell Ocurrences– iBATIS presented the highest number of code smells– new code smells clearly occurred more often than the others in

two systems HW and Ibatis– Smells are not specific to a group of developers or particular

system characteristics.– This result somehow confirmed in the MM case as 5 (out of 6)

new code smells manifested in at least one release.

03/05/23 12Nome do Autor © LES/PUC-Rio

Page 11: An Exploratory Study of Code Smells in Evolving Aspect-Oriented Systems Isela Macia Alessandro Garcia Arndt von Staa.

Frequency of Code Smells is Manifold

• Code Smells that Never Occurred– Some documented code smells never occurred in any of the

target systems– They might represent silly code smells that are usually not

realized even by programmers with little experience (AMI)– It is questionable whether some of these smells are really

smells (VC)– It might be the case that they have very specific definitions that

tend to barely occur in practice (FE)

03/05/23 13Nome do Autor © LES/PUC-Rio

Page 12: An Exploratory Study of Code Smells in Evolving Aspect-Oriented Systems Isela Macia Alessandro Garcia Arndt von Staa.

Frequency of Code Smells is Manifold

• Code Smells with the Highest Frequency– The code smells associated with the problem of replicated

pointcuts (e.g. Redundant Pointcut and Duplicate Pointcut) – Redundant Pointcut accounts for about 20% and 30% of all

anomalies in iBATIS and HW, respectively and Duplicate Pointcut accounts for about 56% in MM

– Anonymous Pointcut increased considerably through system releases

03/05/23 14Nome do Autor © LES/PUC-Rio

Page 13: An Exploratory Study of Code Smells in Evolving Aspect-Oriented Systems Isela Macia Alessandro Garcia Arndt von Staa.

Frequency of Code Smells is Manifold

• Early vs. Late Code Smells– Code smells tended to appear in different stages of the

software projects– The occurrences of Lazy Aspect and Duplicate Pointcut tended

to appear since the first system releases – Composition Bloat tends to appear in later stages due to the

incremental addition of aspects that pick out the same join point

03/05/23 15Nome do Autor © LES/PUC-Rio

Page 14: An Exploratory Study of Code Smells in Evolving Aspect-Oriented Systems Isela Macia Alessandro Garcia Arndt von Staa.

Frequency of Code Smells is Manifold

• Simultaneous Occurrences of Code Smells – Refactoring to God Pointcut and Redundant Pointcut should

take into consideration that this pointcut is likely to be reused in other contexts

– Composition Bloat is usually accompanied by either Redundant Pointcut or Duplicate Pointcut

– Similar situations were observed with respect to Force Join Point and Idle Pointcut

– Anonymous Pointcut and Redundant Pointcut were observed in HW and iBATIS systems

– Many occurrences of the Anonymous Pointcut in IBATIS were also classified as God Pointcut

03/05/23 16Nome do Autor © LES/PUC-Rio

Page 15: An Exploratory Study of Code Smells in Evolving Aspect-Oriented Systems Isela Macia Alessandro Garcia Arndt von Staa.

Refactoring and Code Smell Occurrences

• The Regularity of Rename Refactorings– The “rename” refactoring was consistently one of the most

used techniques in the target systems• Pointcut Refactorings were Frequent

– Move Pointcut– Combine Pointcut – Decompose Pointcut

03/05/23 17Nome do Autor © LES/PUC-Rio

Page 16: An Exploratory Study of Code Smells in Evolving Aspect-Oriented Systems Isela Macia Alessandro Garcia Arndt von Staa.

Refactoring and Code Smell Occurrences

• Refactoring Crosscutting Behavior within Aspects

• Removal of Composition Bloat was often Ignored

• All refactoring that could be performed automatically was

performed manually

• Almost 90% of refactoring in OO programs is performed

manually without the help of tools

03/05/23 18Nome do Autor © LES/PUC-Rio

Page 17: An Exploratory Study of Code Smells in Evolving Aspect-Oriented Systems Isela Macia Alessandro Garcia Arndt von Staa.

Corrective Changes

• Code Smells often led to Corrective Changes– The number of faults related to code smells is greater than the

number of faults that are not related– The categories pointcut declarations and aspect dependences

presented the largest number of faults related to code smells

03/05/23 19Nome do Autor © LES/PUC-Rio

Page 18: An Exploratory Study of Code Smells in Evolving Aspect-Oriented Systems Isela Macia Alessandro Garcia Arndt von Staa.

Corrective Changes

• Code Smells led to Tricky Faults– Pointcut expressions tend to break as a consequence of code

changes– Most of the faults identified in our study were related to Idle

Pointcut and Duplication Pointcut code smells

03/05/23 20Nome do Autor © LES/PUC-Rio

Page 19: An Exploratory Study of Code Smells in Evolving Aspect-Oriented Systems Isela Macia Alessandro Garcia Arndt von Staa.

Corrective Changes

• Code Smells and Faults related to Aspect Dependencies– Occurrences of Duplicate Pointcut and Redundant Pointcut

occurred due to inter-type declarations– No aspect ordering specified– Faults that are not related to code smell occurrences

• Misuse of quantification mechanisms

03/05/23 21Nome do Autor © LES/PUC-Rio

Page 20: An Exploratory Study of Code Smells in Evolving Aspect-Oriented Systems Isela Macia Alessandro Garcia Arndt von Staa.

Study Limitations

• Threats to Construct Validity– Possible errors introduced in the identification of code smell

instances– We used fault reports provided by developers and previously

improved in other study• Threats to Conclusion Validity

– Three releases of MM, four releases of iBATIS, and ten releases of HW were used for the purposes of this study, totaling 17 analyzed systems

– For each application we ensured that significant evolutionary changes took place between releases

03/05/23 22Nome do Autor © LES/PUC-Rio

Page 21: An Exploratory Study of Code Smells in Evolving Aspect-Oriented Systems Isela Macia Alessandro Garcia Arndt von Staa.

Study Limitations

• Threats to Internal Validity– We used systems that were developed by more than 30

programmers with different levels of AOP skills• Threats to External Validity

– We have tried to use applications with different sizes and that were implemented using different methodologies and environments

03/05/23 23Nome do Autor © LES/PUC-Rio

Page 22: An Exploratory Study of Code Smells in Evolving Aspect-Oriented Systems Isela Macia Alessandro Garcia Arndt von Staa.

Related Work

• Definition of Code Smells– Piveta defined five code smells occurring in AO systems– Srivisut extended Piveta’s work in order to define metrics that

help to identify the code smells proposed by him• Refactoring for AOP

– Iwamoto and Zhao investigate the impact of existing OO refactorings on AO programs

– Monteiro and Fernandez propose a collection of 28 AO refactorings

– We analyzed how some of these refactoring techniques are performed in practice

03/05/23 24Nome do Autor © LES/PUC-Rio

Page 23: An Exploratory Study of Code Smells in Evolving Aspect-Oriented Systems Isela Macia Alessandro Garcia Arndt von Staa.

Concluding Remarks

• We presented a new set of code smells observed in AOP • Previously-documented smells were also considered• Many code smells (mainly the new ones) have occurred in

the AO systems due to the lack of a complete catalog for AOP

• We have also observed that many anomalies in AO programs were a mere consequence of bad structure of the OO code

03/05/23 25Nome do Autor © LES/PUC-Rio

Page 24: An Exploratory Study of Code Smells in Evolving Aspect-Oriented Systems Isela Macia Alessandro Garcia Arndt von Staa.

An Exploratory Study of Code Smells inEvolving Aspect-Oriented Systems

Alessandro Garcia ([email protected])

Arndt von Staa ([email protected])

Isela Macia ([email protected])