SlideShare a Scribd company logo
1 of 31
A Multidimensional Empirical Study on
Refactoring Activity

Nikolaos Tsantalis, Victor Guana, Eleni Stroulia, and Abram Hindle
Department of Computer Science and Software Engineering - Concordia University,
Department of Computing Science - University of Alberta, Edmonton, Alberta, Canada
1
What do we want to understand?
Code Refactoring:
“Disciplined technique for restructuring an existing body of code,
altering its internal structure without changing its external behavior” ….

“to improve some of the non-functional attributes of the software”…
“code readability and reduced complexity to improve
the maintainability of the source code, as well as a more expressive
internal architecture or object model to improve extensibility”

Martin Fowler in http://refactoring.com

2
SSRG Lab – University of Alberta
What do we want to understand?

Five research questions that explore the different types of refactorings applied to
different types of sources.
Dimensions:
• The individual contribution of team members on refactoring activities.

• The alignment of refactoring activity with release dates and testing periods.
• The motivation behind the applied refactorings.

3
SSRG Lab – University of Alberta
Why do we want to understand it?
• Help the community better reflect on the actual refactoring practice.
• Increase the awareness of the software maintenance community about the
drivers behind the application of refactorings.
• Help motivate the creation of refactoring tools (e.g., code smell detectors, IDEs)
addressing the actual needs of developers in a principled and empirical manner.

4
SSRG Lab – University of Alberta
How do we want to understand it?
• Three Case Studies (Git Repositories)
Dev. Time
JUnit

12 years (4 analyzed)

Analyzed Rev.
1018 Revisions

Jakarta HTTP Core

7 years (7 analyzed)

1588 revisions

Jakarta HTTP Client

6 years (6 analyzed)

1838 revisions

• Detecting Refactorings: Lightweight version of the UMLDiff algorithm for
differencing object-oriented models.
• Detecting Testing Activity: Semi-automatic testing activity in software evolution
through package organization analysis, keyword and topic analysis and manual
inspection.

5
SSRG Lab – University of Alberta
RQ1: Do software developers perform different
types of refactoring operations on test code and
production code?
• We needed to determine successive revisions in the
repositories, given the nature of the non-linear
commit history of GIT
But.. how?

• Implicit Branching.

• Lightweight version of the UMLDiff algorithm for
differencing object-oriented models + refactoring
detection rules defined by Biegel et al. [1]
6
SSRG Lab – University of Alberta
RQ1: Do software developers perform different
types of refactoring operations on test code and
production code?

7
SSRG Lab – University of Alberta
RQ2: Which developers are responsible for
refactorings?
Identify test-specific and production-specific code entities
JUnit:
Test code is well organized and classes, methods, fields are
located in a junit.tests package since
the beginning of the project.

But.. how?

HTTP Core & Client:
Classes had a prefix of Test or a suffix of Mock
Hybrid approach automatically collecting test classes
following the pattern matching approach, and manually
inspecting the results.
8
SSRG Lab – University of Alberta
RQ2: Which developers are responsible for
refactorings?

9
SSRG Lab – University of Alberta
RQ3: Is there more refactoring activity before
major project releases than after?
We tracked each project major release dates in the public software
release dates + Manually examined their relevance to filter minor
releases such as
• Isolated application of patches
• Major documentation migration
• Change of license types

But.. how?

HTTPCore: project had major releases every 2 months.
JUnit: commit activity decreased substantially 30 days after
the release dates
observation window

40 days before

release

40 days after
10
SSRG Lab – University of Alberta
RQ3: Is there more refactoring activity before
major project releases than after?

HTTP-Client

11
SSRG Lab – University of Alberta
RQ3: Is there more refactoring activity before
major project releases than after?

HTTP-Core
12
SSRG Lab – University of Alberta
RQ3: Is there more refactoring activity before
major project releases than after?

JUnit
13
SSRG Lab – University of Alberta
RQ4: Is refactoring activity on production code
preceded by the addition/modification of test code?
Extraction of test code update periods
1.
2.
3.
4.
5.

Detected additions/modifications of Test classes in the commit history
Created plots of activity
Focused on periods with contiguous and intense activity
Manually inspected the periods to discard False positives
The last day of each period was set as the pivot point in our window
analysis

14
SSRG Lab – University of Alberta
RQ4: Is refactoring activity on production code
preceded by the addition/modification of test code?

HTTP-Client

15
SSRG Lab – University of Alberta
RQ4: Is refactoring activity on production code
preceded by the addition/modification of test code?

HTTP-Core
16
SSRG Lab – University of Alberta
RQ4: Is refactoring activity on production code
preceded by the addition/modification of test code?

JUnit
17
SSRG Lab – University of Alberta
RQ5: What is the purpose of
the applied refactorings?
Goal: Find the reason behind the application of the detected refactorings.
1.

2.
3.
4.

Inspected a randomly selected subset of refactorings to come up with
some basic categories of motivations.
Defined rules to classify a refactoring instance in each of the basic
categories.
Labeled all refactoring instances applying the classification rules.
In the case of new emerging categories, the classification rules were
updated and all instances were re-labelled.

18
SSRG Lab – University of Alberta
We classified 210
Extract Method instances in total

Extract Method is known as the
“Swiss Army knife” of refactorings

19
SSRG Lab – University of Alberta
Facilitate Extension
private boolean isShadowed(Method method, List<Method> results) {
for (Method each : results) {
if (each.getName().equals(method.getName()))
return true;
}
return false;
}
BEFORE
private boolean isShadowed(Method method, List<Method> results) {
for (Method each : results) {
if (isShadowed(method, each))
return true;
}
return false;
}
private boolean isShadowed(Method current, Method previous) {
if (! previous.getName().equals(current.getName()))
return false;
//additional conditions examined
if (...)
AFTER
}
20
Backward Compatibility
public void writeTo(final OutputStream out, int mode) {
InputStream in = new FileInputStream(this.file);
byte[] tmp = new byte[4096];
int l;
while ((l = in.read(tmp)) != -1) {
out.write(tmp, 0, l);
}
out.flush();
}
BEFORE
@Deprecated
public void writeTo(final OutputStream out, int mode) {
writeTo(out);
}
public void writeTo(final OutputStream out) {
InputStream in = new FileInputStream(this.file);
byte[] tmp = new byte[4096];
int l;
while ((l = in.read(tmp)) != -1) {
out.write(tmp, 0, l);
}
out.flush();
}
AFTER

unused

21
Encapsulate Field
public static Properties fPreferences;
private static void readPreferences() {
fPreferences = new Properties(fPreferences);
fPreferences.load(is);
}
public static String getPreference(String key) {
return fPreferences.getProperty(key);
}
BEFORE
private static Properties fPreferences;
private static void readPreferences() {
setPreferences(new Properties(getPreferences()));
getPreferences().load(is);
}
public static String getPreference(String key) {
return getPreferences().getProperty(key);
}
protected static void setPreferences(Properties preferences) {
fPreferences = preferences;
}
protected static Properties getPreferences() {
return fPreferences;
}
AFTER

22
Hide Message Chain
public boolean isShadowedBy(FrameworkField otherMember) {
return otherMember.getField().getName().equals(this.getField().getName());
}
BEFORE

public boolean isShadowedBy(FrameworkField otherMember) {
return otherMember.getName().equals(getName());
}
private String getName() {
return this.getField().getName();
}

AFTER

23
Introduce Factory Method
public Runner runnerForClass(Class<?> testClass) throws Throwable {
List<RunnerBuilder> builders= Arrays.asList(
new IgnoredBuilder(),
new AnnotatedBuilder(this),
suiteMethodBuilder(),
new JUnit3Builder(),
new JUnit4Builder());
}
BEFORE
public Runner runnerForClass(Class<?> testClass) throws Throwable {
List<RunnerBuilder> builders= Arrays.asList(
ignoredBuilder(),
annotatedBuilder(),
suiteMethodBuilder(),
junit3Builder(),
junit4Builder());
}
protected AnnotatedBuilder annotatedBuilder() {
return new AnnotatedBuilder(this);
}

AFTER
24
RQ5: What is the purpose of
the applied refactorings?
We found three main motivations for the application of the extract method
refactoring: code smell resolution, extension and backward compatibility.

Extract
Method
Refactoring

44%

44%

12%

25
SSRG Lab – University of Alberta
We classified 70
Inheritance-related refactorings in total

What about Inheritance related refactorings?

26
SSRG Lab – University of Alberta
RQ5: What is the purpose of
the applied refactorings?
We found three main motivations for the application of the extract method
refactoring: code smell resolution, extension and refinement of abstraction level.

31%
Inheritance
Related
Refactorings

20%
49%

27
SSRG Lab – University of Alberta
Bird's-eye-view Conclusions
RQ1: Do software developers perform different types of refactoring operations on
test code and production code?
In production code: Design improvements such as, resolution of code
smells and modularization.
In test code: Internal reorganization of the classes of each project into
packages and renaming of classes for conceptual reasons.

RQ2. Which developers are responsible for refactorings?
Refactorings were mainly fulfilled by a single developer acting as a refactoring
manager.
Managers share refactoring responsibilities in both production and test code.

28
SSRG Lab – University of Alberta
Bird's-eye-view Conclusions
RQ3. Is there more refactoring activity before major project releases than after?
Refactoring activity is significantly more frequent before a release than after. We
believe this activity is motivated by the desire to improve the design, and prepare
the code for future extensions, right before releasing a stable API.

RQ4: Is refactoring activity on production code preceded by the addition or
modification of test code?

A tight alignment between refactoring activities and test code updates.
Testing and refactoring are dependent implying the adoption of test-driven
refactoring practices in the examined projects.

29
SSRG Lab – University of Alberta
Bird's-eye-view Conclusions
RQ5: What is the purpose of the applied refactorings?
Extract Method refactoring:
• Code smells: The decomposition of methods was the most dominant
motivation

• Facilitating Extension: Introduction of Factory Methods
Inheritance related refactorings:

• Removal of duplicate code and the generalization of abstraction.
• Decomposition of interfaces and specialization of abstraction were rarely
applied practices.

30
SSRG Lab – University of Alberta
Bird's-eye-view Conclusions
RQ1: Do software developers perform different types of refactoring operations
on test code and production code?
RQ2. Which developers are responsible for refactorings?
RQ3. Is there more refactoring activity before major project releases than after?
RQ4: Is refactoring activity on production code preceded by the addition or
modification of test code?
RQ5: What is the purpose of the applied refactorings?

tsantalis@cse.concordia.ca
guana@ualberta.ca

31
SSRG Lab – University of Alberta

More Related Content

What's hot

Automated Evolution of Feature Logging Statement Levels Using Git Histories a...
Automated Evolution of Feature Logging Statement Levels Using Git Histories a...Automated Evolution of Feature Logging Statement Levels Using Git Histories a...
Automated Evolution of Feature Logging Statement Levels Using Git Histories a...
Raffi Khatchadourian
 
Known XML Vulnerabilities Are Still a Threat to Popular Parsers ! & Open Sour...
Known XML Vulnerabilities Are Still a Threat to Popular Parsers ! & Open Sour...Known XML Vulnerabilities Are Still a Threat to Popular Parsers ! & Open Sour...
Known XML Vulnerabilities Are Still a Threat to Popular Parsers ! & Open Sour...
Lionel Briand
 
Actor Concurrency Bugs: A Comprehensive Study on Symptoms, Root Causes, API U...
Actor Concurrency Bugs: A Comprehensive Study on Symptoms, Root Causes, API U...Actor Concurrency Bugs: A Comprehensive Study on Symptoms, Root Causes, API U...
Actor Concurrency Bugs: A Comprehensive Study on Symptoms, Root Causes, API U...
Raffi Khatchadourian
 
Cross-project Defect Prediction Using A Connectivity-based Unsupervised Class...
Cross-project Defect Prediction Using A Connectivity-based Unsupervised Class...Cross-project Defect Prediction Using A Connectivity-based Unsupervised Class...
Cross-project Defect Prediction Using A Connectivity-based Unsupervised Class...
Feng Zhang
 
The Use of Development History in Software Refactoring Using a Multi-Objectiv...
The Use of Development History in Software Refactoring Using a Multi-Objectiv...The Use of Development History in Software Refactoring Using a Multi-Objectiv...
The Use of Development History in Software Refactoring Using a Multi-Objectiv...
Ali Ouni
 
Crunching Molecules and Numbers in R
Crunching Molecules and Numbers in RCrunching Molecules and Numbers in R
Crunching Molecules and Numbers in R
Rajarshi Guha
 

What's hot (20)

ESSIR LivingKnowledge DiversityEngine tutorial
ESSIR LivingKnowledge DiversityEngine tutorialESSIR LivingKnowledge DiversityEngine tutorial
ESSIR LivingKnowledge DiversityEngine tutorial
 
Review Participation in Modern Code Review: An Empirical Study of the Android...
Review Participation in Modern Code Review: An Empirical Study of the Android...Review Participation in Modern Code Review: An Empirical Study of the Android...
Review Participation in Modern Code Review: An Empirical Study of the Android...
 
Automated Evolution of Feature Logging Statement Levels Using Git Histories a...
Automated Evolution of Feature Logging Statement Levels Using Git Histories a...Automated Evolution of Feature Logging Statement Levels Using Git Histories a...
Automated Evolution of Feature Logging Statement Levels Using Git Histories a...
 
Software Defect Prediction on Unlabeled Datasets
Software Defect Prediction on Unlabeled DatasetsSoftware Defect Prediction on Unlabeled Datasets
Software Defect Prediction on Unlabeled Datasets
 
Known XML Vulnerabilities Are Still a Threat to Popular Parsers ! & Open Sour...
Known XML Vulnerabilities Are Still a Threat to Popular Parsers ! & Open Sour...Known XML Vulnerabilities Are Still a Threat to Popular Parsers ! & Open Sour...
Known XML Vulnerabilities Are Still a Threat to Popular Parsers ! & Open Sour...
 
Actor Concurrency Bugs: A Comprehensive Study on Symptoms, Root Causes, API U...
Actor Concurrency Bugs: A Comprehensive Study on Symptoms, Root Causes, API U...Actor Concurrency Bugs: A Comprehensive Study on Symptoms, Root Causes, API U...
Actor Concurrency Bugs: A Comprehensive Study on Symptoms, Root Causes, API U...
 
QTP Automation Testing Tutorial 7
QTP Automation Testing Tutorial 7QTP Automation Testing Tutorial 7
QTP Automation Testing Tutorial 7
 
Opal Hermes - towards representative benchmarks
Opal  Hermes - towards representative benchmarksOpal  Hermes - towards representative benchmarks
Opal Hermes - towards representative benchmarks
 
Dissertation Defense
Dissertation DefenseDissertation Defense
Dissertation Defense
 
Cross-project Defect Prediction Using A Connectivity-based Unsupervised Class...
Cross-project Defect Prediction Using A Connectivity-based Unsupervised Class...Cross-project Defect Prediction Using A Connectivity-based Unsupervised Class...
Cross-project Defect Prediction Using A Connectivity-based Unsupervised Class...
 
Deep API Learning (FSE 2016)
Deep API Learning (FSE 2016)Deep API Learning (FSE 2016)
Deep API Learning (FSE 2016)
 
Jpylyzer, a validation and feature extraction tool developed in SCAPE project
Jpylyzer, a validation and feature extraction tool developed in SCAPE projectJpylyzer, a validation and feature extraction tool developed in SCAPE project
Jpylyzer, a validation and feature extraction tool developed in SCAPE project
 
Runtime Behavior of JavaScript Programs
Runtime Behavior of JavaScript ProgramsRuntime Behavior of JavaScript Programs
Runtime Behavior of JavaScript Programs
 
Fabrizio pastore TORACLE-2021 @ESEC/FSE 2021
Fabrizio pastore TORACLE-2021 @ESEC/FSE 2021Fabrizio pastore TORACLE-2021 @ESEC/FSE 2021
Fabrizio pastore TORACLE-2021 @ESEC/FSE 2021
 
Mutation Testing Workshop at Ericsson, Kista, Sweden
Mutation Testing Workshop at Ericsson, Kista, SwedenMutation Testing Workshop at Ericsson, Kista, Sweden
Mutation Testing Workshop at Ericsson, Kista, Sweden
 
Data collection for software defect prediction
Data collection for software defect predictionData collection for software defect prediction
Data collection for software defect prediction
 
QTP Automation Testing Tutorial 6
QTP Automation Testing Tutorial 6QTP Automation Testing Tutorial 6
QTP Automation Testing Tutorial 6
 
The Use of Development History in Software Refactoring Using a Multi-Objectiv...
The Use of Development History in Software Refactoring Using a Multi-Objectiv...The Use of Development History in Software Refactoring Using a Multi-Objectiv...
The Use of Development History in Software Refactoring Using a Multi-Objectiv...
 
ICSME 2016: Search-Based Peer Reviewers Recommendation in Modern Code Review
ICSME 2016: Search-Based Peer Reviewers Recommendation in Modern Code ReviewICSME 2016: Search-Based Peer Reviewers Recommendation in Modern Code Review
ICSME 2016: Search-Based Peer Reviewers Recommendation in Modern Code Review
 
Crunching Molecules and Numbers in R
Crunching Molecules and Numbers in RCrunching Molecules and Numbers in R
Crunching Molecules and Numbers in R
 

Similar to A Multidimensional Empirical Study on Refactoring Activity

Similar to A Multidimensional Empirical Study on Refactoring Activity (20)

CASCON 2023 Most Influential Paper Award Talk
CASCON 2023 Most Influential Paper Award TalkCASCON 2023 Most Influential Paper Award Talk
CASCON 2023 Most Influential Paper Award Talk
 
What to expect from Java 9
What to expect from Java 9What to expect from Java 9
What to expect from Java 9
 
Inria Tech Talk : Comment améliorer la qualité de vos logiciels avec STAMP
Inria Tech Talk : Comment améliorer la qualité de vos logiciels avec STAMPInria Tech Talk : Comment améliorer la qualité de vos logiciels avec STAMP
Inria Tech Talk : Comment améliorer la qualité de vos logiciels avec STAMP
 
Microservices Part 4: Functional Reactive Programming
Microservices Part 4: Functional Reactive ProgrammingMicroservices Part 4: Functional Reactive Programming
Microservices Part 4: Functional Reactive Programming
 
Java 7: Quo vadis?
Java 7: Quo vadis?Java 7: Quo vadis?
Java 7: Quo vadis?
 
INFORMATICA Training, Online INFORMATICA Training
INFORMATICA Training, Online INFORMATICA Training INFORMATICA Training, Online INFORMATICA Training
INFORMATICA Training, Online INFORMATICA Training
 
INFORMATICA Training, Online INFORMATICA Training
INFORMATICA Training, Online INFORMATICA Training INFORMATICA Training, Online INFORMATICA Training
INFORMATICA Training, Online INFORMATICA Training
 
informatica 9.5 online training| informatica training online ...
informatica 9.5 online training| informatica training online ...informatica 9.5 online training| informatica training online ...
informatica 9.5 online training| informatica training online ...
 
INFORMATICA ONLINE TRAINING
INFORMATICA ONLINE TRAININGINFORMATICA ONLINE TRAINING
INFORMATICA ONLINE TRAINING
 
INFORMATICA ONLINE TRAINING
INFORMATICA ONLINE TRAININGINFORMATICA ONLINE TRAINING
INFORMATICA ONLINE TRAINING
 
INFORMATICA ONLINE TRAINING
INFORMATICA ONLINE TRAININGINFORMATICA ONLINE TRAINING
INFORMATICA ONLINE TRAINING
 
Informatica
InformaticaInformatica
Informatica
 
Seeding a Tree in a Gherkin
Seeding a Tree in a GherkinSeeding a Tree in a Gherkin
Seeding a Tree in a Gherkin
 
ExSchema - ICSM'13
ExSchema - ICSM'13ExSchema - ICSM'13
ExSchema - ICSM'13
 
Resilience Engineering: A field of study, a community, and some perspective s...
Resilience Engineering: A field of study, a community, and some perspective s...Resilience Engineering: A field of study, a community, and some perspective s...
Resilience Engineering: A field of study, a community, and some perspective s...
 
Ensuring Software Quality Through Test Automation- Naperville Software Develo...
Ensuring Software Quality Through Test Automation- Naperville Software Develo...Ensuring Software Quality Through Test Automation- Naperville Software Develo...
Ensuring Software Quality Through Test Automation- Naperville Software Develo...
 
Git influencer - PPT
Git influencer - PPTGit influencer - PPT
Git influencer - PPT
 
Graph-Based Source Code Analysis of JavaScript Repositories
Graph-Based Source Code Analysis of JavaScript Repositories Graph-Based Source Code Analysis of JavaScript Repositories
Graph-Based Source Code Analysis of JavaScript Repositories
 
Of Changes and Their History
Of Changes and Their HistoryOf Changes and Their History
Of Changes and Their History
 
Geant4 physics validation on the GRID
Geant4 physics validation on the GRIDGeant4 physics validation on the GRID
Geant4 physics validation on the GRID
 

More from Nikolaos Tsantalis

Accurate and Efficient Refactoring Detection in Commit History
Accurate and Efficient Refactoring Detection in Commit HistoryAccurate and Efficient Refactoring Detection in Commit History
Accurate and Efficient Refactoring Detection in Commit History
Nikolaos Tsantalis
 
Improving the Unification of Software Clones Using Tree and Graph Matching Al...
Improving the Unification of Software Clones Using Tree and Graph Matching Al...Improving the Unification of Software Clones Using Tree and Graph Matching Al...
Improving the Unification of Software Clones Using Tree and Graph Matching Al...
Nikolaos Tsantalis
 
Code Smell Research: History and Future Directions
Code Smell Research: History and Future DirectionsCode Smell Research: History and Future Directions
Code Smell Research: History and Future Directions
Nikolaos Tsantalis
 
Preventive Software Maintenance: The Past, the Present, the Future
Preventive Software Maintenance: The Past, the Present, the FuturePreventive Software Maintenance: The Past, the Present, the Future
Preventive Software Maintenance: The Past, the Present, the Future
Nikolaos Tsantalis
 
An Empirical Study of Duplication in Cascading Style Sheets
An Empirical Study of Duplication in Cascading Style SheetsAn Empirical Study of Duplication in Cascading Style Sheets
An Empirical Study of Duplication in Cascading Style Sheets
Nikolaos Tsantalis
 
Ranking Refactoring Suggestions based on Historical Volatility
Ranking Refactoring Suggestions based on Historical VolatilityRanking Refactoring Suggestions based on Historical Volatility
Ranking Refactoring Suggestions based on Historical Volatility
Nikolaos Tsantalis
 
Feature Detection in Ajax-enabled Web Applications
Feature Detection in Ajax-enabled Web ApplicationsFeature Detection in Ajax-enabled Web Applications
Feature Detection in Ajax-enabled Web Applications
Nikolaos Tsantalis
 
Unification and Refactoring of Clones
Unification and Refactoring of ClonesUnification and Refactoring of Clones
Unification and Refactoring of Clones
Nikolaos Tsantalis
 

More from Nikolaos Tsantalis (16)

Refactoring Mining - The key to unlock software evolution
Refactoring Mining - The key to unlock software evolutionRefactoring Mining - The key to unlock software evolution
Refactoring Mining - The key to unlock software evolution
 
SANER 2019 Most Influential Paper Talk
SANER 2019 Most Influential Paper TalkSANER 2019 Most Influential Paper Talk
SANER 2019 Most Influential Paper Talk
 
Accurate and Efficient Refactoring Detection in Commit History
Accurate and Efficient Refactoring Detection in Commit HistoryAccurate and Efficient Refactoring Detection in Commit History
Accurate and Efficient Refactoring Detection in Commit History
 
Clone Refactoring with Lambda Expressions
Clone Refactoring with Lambda ExpressionsClone Refactoring with Lambda Expressions
Clone Refactoring with Lambda Expressions
 
Why We Refactor? Confessions of GitHub Contributors
Why We Refactor? Confessions of GitHub ContributorsWhy We Refactor? Confessions of GitHub Contributors
Why We Refactor? Confessions of GitHub Contributors
 
Migrating cascading style sheets to preprocessors
Migrating cascading style sheets to preprocessorsMigrating cascading style sheets to preprocessors
Migrating cascading style sheets to preprocessors
 
JDeodorant: Clone Refactoring
JDeodorant: Clone RefactoringJDeodorant: Clone Refactoring
JDeodorant: Clone Refactoring
 
An empirical study on the use of CSS preprocessors
An empirical study on the use of CSS preprocessorsAn empirical study on the use of CSS preprocessors
An empirical study on the use of CSS preprocessors
 
An Empirical Study on the Use of CSS Preprocessors
An Empirical Study on the Use of CSS PreprocessorsAn Empirical Study on the Use of CSS Preprocessors
An Empirical Study on the Use of CSS Preprocessors
 
Improving the Unification of Software Clones Using Tree and Graph Matching Al...
Improving the Unification of Software Clones Using Tree and Graph Matching Al...Improving the Unification of Software Clones Using Tree and Graph Matching Al...
Improving the Unification of Software Clones Using Tree and Graph Matching Al...
 
Code Smell Research: History and Future Directions
Code Smell Research: History and Future DirectionsCode Smell Research: History and Future Directions
Code Smell Research: History and Future Directions
 
Preventive Software Maintenance: The Past, the Present, the Future
Preventive Software Maintenance: The Past, the Present, the FuturePreventive Software Maintenance: The Past, the Present, the Future
Preventive Software Maintenance: The Past, the Present, the Future
 
An Empirical Study of Duplication in Cascading Style Sheets
An Empirical Study of Duplication in Cascading Style SheetsAn Empirical Study of Duplication in Cascading Style Sheets
An Empirical Study of Duplication in Cascading Style Sheets
 
Ranking Refactoring Suggestions based on Historical Volatility
Ranking Refactoring Suggestions based on Historical VolatilityRanking Refactoring Suggestions based on Historical Volatility
Ranking Refactoring Suggestions based on Historical Volatility
 
Feature Detection in Ajax-enabled Web Applications
Feature Detection in Ajax-enabled Web ApplicationsFeature Detection in Ajax-enabled Web Applications
Feature Detection in Ajax-enabled Web Applications
 
Unification and Refactoring of Clones
Unification and Refactoring of ClonesUnification and Refactoring of Clones
Unification and Refactoring of Clones
 

Recently uploaded

SCIENCE-4-QUARTER4-WEEK-4-PPT-1 (1).pptx
SCIENCE-4-QUARTER4-WEEK-4-PPT-1 (1).pptxSCIENCE-4-QUARTER4-WEEK-4-PPT-1 (1).pptx
SCIENCE-4-QUARTER4-WEEK-4-PPT-1 (1).pptx
RizalinePalanog2
 
Biopesticide (2).pptx .This slides helps to know the different types of biop...
Biopesticide (2).pptx  .This slides helps to know the different types of biop...Biopesticide (2).pptx  .This slides helps to know the different types of biop...
Biopesticide (2).pptx .This slides helps to know the different types of biop...
RohitNehra6
 
Labelling Requirements and Label Claims for Dietary Supplements and Recommend...
Labelling Requirements and Label Claims for Dietary Supplements and Recommend...Labelling Requirements and Label Claims for Dietary Supplements and Recommend...
Labelling Requirements and Label Claims for Dietary Supplements and Recommend...
Lokesh Kothari
 
Formation of low mass protostars and their circumstellar disks
Formation of low mass protostars and their circumstellar disksFormation of low mass protostars and their circumstellar disks
Formation of low mass protostars and their circumstellar disks
Sérgio Sacani
 
Hubble Asteroid Hunter III. Physical properties of newly found asteroids
Hubble Asteroid Hunter III. Physical properties of newly found asteroidsHubble Asteroid Hunter III. Physical properties of newly found asteroids
Hubble Asteroid Hunter III. Physical properties of newly found asteroids
Sérgio Sacani
 
Pests of cotton_Sucking_Pests_Dr.UPR.pdf
Pests of cotton_Sucking_Pests_Dr.UPR.pdfPests of cotton_Sucking_Pests_Dr.UPR.pdf
Pests of cotton_Sucking_Pests_Dr.UPR.pdf
PirithiRaju
 
Chemical Tests; flame test, positive and negative ions test Edexcel Internati...
Chemical Tests; flame test, positive and negative ions test Edexcel Internati...Chemical Tests; flame test, positive and negative ions test Edexcel Internati...
Chemical Tests; flame test, positive and negative ions test Edexcel Internati...
ssuser79fe74
 
Pests of cotton_Borer_Pests_Binomics_Dr.UPR.pdf
Pests of cotton_Borer_Pests_Binomics_Dr.UPR.pdfPests of cotton_Borer_Pests_Binomics_Dr.UPR.pdf
Pests of cotton_Borer_Pests_Binomics_Dr.UPR.pdf
PirithiRaju
 

Recently uploaded (20)

SCIENCE-4-QUARTER4-WEEK-4-PPT-1 (1).pptx
SCIENCE-4-QUARTER4-WEEK-4-PPT-1 (1).pptxSCIENCE-4-QUARTER4-WEEK-4-PPT-1 (1).pptx
SCIENCE-4-QUARTER4-WEEK-4-PPT-1 (1).pptx
 
Green chemistry and Sustainable development.pptx
Green chemistry  and Sustainable development.pptxGreen chemistry  and Sustainable development.pptx
Green chemistry and Sustainable development.pptx
 
Forensic Biology & Its biological significance.pdf
Forensic Biology & Its biological significance.pdfForensic Biology & Its biological significance.pdf
Forensic Biology & Its biological significance.pdf
 
Nanoparticles synthesis and characterization​ ​
Nanoparticles synthesis and characterization​  ​Nanoparticles synthesis and characterization​  ​
Nanoparticles synthesis and characterization​ ​
 
Biopesticide (2).pptx .This slides helps to know the different types of biop...
Biopesticide (2).pptx  .This slides helps to know the different types of biop...Biopesticide (2).pptx  .This slides helps to know the different types of biop...
Biopesticide (2).pptx .This slides helps to know the different types of biop...
 
Labelling Requirements and Label Claims for Dietary Supplements and Recommend...
Labelling Requirements and Label Claims for Dietary Supplements and Recommend...Labelling Requirements and Label Claims for Dietary Supplements and Recommend...
Labelling Requirements and Label Claims for Dietary Supplements and Recommend...
 
Formation of low mass protostars and their circumstellar disks
Formation of low mass protostars and their circumstellar disksFormation of low mass protostars and their circumstellar disks
Formation of low mass protostars and their circumstellar disks
 
Zoology 4th semester series (krishna).pdf
Zoology 4th semester series (krishna).pdfZoology 4th semester series (krishna).pdf
Zoology 4th semester series (krishna).pdf
 
All-domain Anomaly Resolution Office U.S. Department of Defense (U) Case: “Eg...
All-domain Anomaly Resolution Office U.S. Department of Defense (U) Case: “Eg...All-domain Anomaly Resolution Office U.S. Department of Defense (U) Case: “Eg...
All-domain Anomaly Resolution Office U.S. Department of Defense (U) Case: “Eg...
 
Stunning ➥8448380779▻ Call Girls In Panchshil Enclave Delhi NCR
Stunning ➥8448380779▻ Call Girls In Panchshil Enclave Delhi NCRStunning ➥8448380779▻ Call Girls In Panchshil Enclave Delhi NCR
Stunning ➥8448380779▻ Call Girls In Panchshil Enclave Delhi NCR
 
VIRUSES structure and classification ppt by Dr.Prince C P
VIRUSES structure and classification ppt by Dr.Prince C PVIRUSES structure and classification ppt by Dr.Prince C P
VIRUSES structure and classification ppt by Dr.Prince C P
 
Hubble Asteroid Hunter III. Physical properties of newly found asteroids
Hubble Asteroid Hunter III. Physical properties of newly found asteroidsHubble Asteroid Hunter III. Physical properties of newly found asteroids
Hubble Asteroid Hunter III. Physical properties of newly found asteroids
 
Pests of cotton_Sucking_Pests_Dr.UPR.pdf
Pests of cotton_Sucking_Pests_Dr.UPR.pdfPests of cotton_Sucking_Pests_Dr.UPR.pdf
Pests of cotton_Sucking_Pests_Dr.UPR.pdf
 
Chemical Tests; flame test, positive and negative ions test Edexcel Internati...
Chemical Tests; flame test, positive and negative ions test Edexcel Internati...Chemical Tests; flame test, positive and negative ions test Edexcel Internati...
Chemical Tests; flame test, positive and negative ions test Edexcel Internati...
 
Botany krishna series 2nd semester Only Mcq type questions
Botany krishna series 2nd semester Only Mcq type questionsBotany krishna series 2nd semester Only Mcq type questions
Botany krishna series 2nd semester Only Mcq type questions
 
Hire 💕 9907093804 Hooghly Call Girls Service Call Girls Agency
Hire 💕 9907093804 Hooghly Call Girls Service Call Girls AgencyHire 💕 9907093804 Hooghly Call Girls Service Call Girls Agency
Hire 💕 9907093804 Hooghly Call Girls Service Call Girls Agency
 
Isotopic evidence of long-lived volcanism on Io
Isotopic evidence of long-lived volcanism on IoIsotopic evidence of long-lived volcanism on Io
Isotopic evidence of long-lived volcanism on Io
 
Pests of cotton_Borer_Pests_Binomics_Dr.UPR.pdf
Pests of cotton_Borer_Pests_Binomics_Dr.UPR.pdfPests of cotton_Borer_Pests_Binomics_Dr.UPR.pdf
Pests of cotton_Borer_Pests_Binomics_Dr.UPR.pdf
 
High Class Escorts in Hyderabad ₹7.5k Pick Up & Drop With Cash Payment 969456...
High Class Escorts in Hyderabad ₹7.5k Pick Up & Drop With Cash Payment 969456...High Class Escorts in Hyderabad ₹7.5k Pick Up & Drop With Cash Payment 969456...
High Class Escorts in Hyderabad ₹7.5k Pick Up & Drop With Cash Payment 969456...
 
SAMASTIPUR CALL GIRL 7857803690 LOW PRICE ESCORT SERVICE
SAMASTIPUR CALL GIRL 7857803690  LOW PRICE  ESCORT SERVICESAMASTIPUR CALL GIRL 7857803690  LOW PRICE  ESCORT SERVICE
SAMASTIPUR CALL GIRL 7857803690 LOW PRICE ESCORT SERVICE
 

A Multidimensional Empirical Study on Refactoring Activity

  • 1. A Multidimensional Empirical Study on Refactoring Activity Nikolaos Tsantalis, Victor Guana, Eleni Stroulia, and Abram Hindle Department of Computer Science and Software Engineering - Concordia University, Department of Computing Science - University of Alberta, Edmonton, Alberta, Canada 1
  • 2. What do we want to understand? Code Refactoring: “Disciplined technique for restructuring an existing body of code, altering its internal structure without changing its external behavior” …. “to improve some of the non-functional attributes of the software”… “code readability and reduced complexity to improve the maintainability of the source code, as well as a more expressive internal architecture or object model to improve extensibility” Martin Fowler in http://refactoring.com 2 SSRG Lab – University of Alberta
  • 3. What do we want to understand? Five research questions that explore the different types of refactorings applied to different types of sources. Dimensions: • The individual contribution of team members on refactoring activities. • The alignment of refactoring activity with release dates and testing periods. • The motivation behind the applied refactorings. 3 SSRG Lab – University of Alberta
  • 4. Why do we want to understand it? • Help the community better reflect on the actual refactoring practice. • Increase the awareness of the software maintenance community about the drivers behind the application of refactorings. • Help motivate the creation of refactoring tools (e.g., code smell detectors, IDEs) addressing the actual needs of developers in a principled and empirical manner. 4 SSRG Lab – University of Alberta
  • 5. How do we want to understand it? • Three Case Studies (Git Repositories) Dev. Time JUnit 12 years (4 analyzed) Analyzed Rev. 1018 Revisions Jakarta HTTP Core 7 years (7 analyzed) 1588 revisions Jakarta HTTP Client 6 years (6 analyzed) 1838 revisions • Detecting Refactorings: Lightweight version of the UMLDiff algorithm for differencing object-oriented models. • Detecting Testing Activity: Semi-automatic testing activity in software evolution through package organization analysis, keyword and topic analysis and manual inspection. 5 SSRG Lab – University of Alberta
  • 6. RQ1: Do software developers perform different types of refactoring operations on test code and production code? • We needed to determine successive revisions in the repositories, given the nature of the non-linear commit history of GIT But.. how? • Implicit Branching. • Lightweight version of the UMLDiff algorithm for differencing object-oriented models + refactoring detection rules defined by Biegel et al. [1] 6 SSRG Lab – University of Alberta
  • 7. RQ1: Do software developers perform different types of refactoring operations on test code and production code? 7 SSRG Lab – University of Alberta
  • 8. RQ2: Which developers are responsible for refactorings? Identify test-specific and production-specific code entities JUnit: Test code is well organized and classes, methods, fields are located in a junit.tests package since the beginning of the project. But.. how? HTTP Core & Client: Classes had a prefix of Test or a suffix of Mock Hybrid approach automatically collecting test classes following the pattern matching approach, and manually inspecting the results. 8 SSRG Lab – University of Alberta
  • 9. RQ2: Which developers are responsible for refactorings? 9 SSRG Lab – University of Alberta
  • 10. RQ3: Is there more refactoring activity before major project releases than after? We tracked each project major release dates in the public software release dates + Manually examined their relevance to filter minor releases such as • Isolated application of patches • Major documentation migration • Change of license types But.. how? HTTPCore: project had major releases every 2 months. JUnit: commit activity decreased substantially 30 days after the release dates observation window 40 days before release 40 days after 10 SSRG Lab – University of Alberta
  • 11. RQ3: Is there more refactoring activity before major project releases than after? HTTP-Client 11 SSRG Lab – University of Alberta
  • 12. RQ3: Is there more refactoring activity before major project releases than after? HTTP-Core 12 SSRG Lab – University of Alberta
  • 13. RQ3: Is there more refactoring activity before major project releases than after? JUnit 13 SSRG Lab – University of Alberta
  • 14. RQ4: Is refactoring activity on production code preceded by the addition/modification of test code? Extraction of test code update periods 1. 2. 3. 4. 5. Detected additions/modifications of Test classes in the commit history Created plots of activity Focused on periods with contiguous and intense activity Manually inspected the periods to discard False positives The last day of each period was set as the pivot point in our window analysis 14 SSRG Lab – University of Alberta
  • 15. RQ4: Is refactoring activity on production code preceded by the addition/modification of test code? HTTP-Client 15 SSRG Lab – University of Alberta
  • 16. RQ4: Is refactoring activity on production code preceded by the addition/modification of test code? HTTP-Core 16 SSRG Lab – University of Alberta
  • 17. RQ4: Is refactoring activity on production code preceded by the addition/modification of test code? JUnit 17 SSRG Lab – University of Alberta
  • 18. RQ5: What is the purpose of the applied refactorings? Goal: Find the reason behind the application of the detected refactorings. 1. 2. 3. 4. Inspected a randomly selected subset of refactorings to come up with some basic categories of motivations. Defined rules to classify a refactoring instance in each of the basic categories. Labeled all refactoring instances applying the classification rules. In the case of new emerging categories, the classification rules were updated and all instances were re-labelled. 18 SSRG Lab – University of Alberta
  • 19. We classified 210 Extract Method instances in total Extract Method is known as the “Swiss Army knife” of refactorings 19 SSRG Lab – University of Alberta
  • 20. Facilitate Extension private boolean isShadowed(Method method, List<Method> results) { for (Method each : results) { if (each.getName().equals(method.getName())) return true; } return false; } BEFORE private boolean isShadowed(Method method, List<Method> results) { for (Method each : results) { if (isShadowed(method, each)) return true; } return false; } private boolean isShadowed(Method current, Method previous) { if (! previous.getName().equals(current.getName())) return false; //additional conditions examined if (...) AFTER } 20
  • 21. Backward Compatibility public void writeTo(final OutputStream out, int mode) { InputStream in = new FileInputStream(this.file); byte[] tmp = new byte[4096]; int l; while ((l = in.read(tmp)) != -1) { out.write(tmp, 0, l); } out.flush(); } BEFORE @Deprecated public void writeTo(final OutputStream out, int mode) { writeTo(out); } public void writeTo(final OutputStream out) { InputStream in = new FileInputStream(this.file); byte[] tmp = new byte[4096]; int l; while ((l = in.read(tmp)) != -1) { out.write(tmp, 0, l); } out.flush(); } AFTER unused 21
  • 22. Encapsulate Field public static Properties fPreferences; private static void readPreferences() { fPreferences = new Properties(fPreferences); fPreferences.load(is); } public static String getPreference(String key) { return fPreferences.getProperty(key); } BEFORE private static Properties fPreferences; private static void readPreferences() { setPreferences(new Properties(getPreferences())); getPreferences().load(is); } public static String getPreference(String key) { return getPreferences().getProperty(key); } protected static void setPreferences(Properties preferences) { fPreferences = preferences; } protected static Properties getPreferences() { return fPreferences; } AFTER 22
  • 23. Hide Message Chain public boolean isShadowedBy(FrameworkField otherMember) { return otherMember.getField().getName().equals(this.getField().getName()); } BEFORE public boolean isShadowedBy(FrameworkField otherMember) { return otherMember.getName().equals(getName()); } private String getName() { return this.getField().getName(); } AFTER 23
  • 24. Introduce Factory Method public Runner runnerForClass(Class<?> testClass) throws Throwable { List<RunnerBuilder> builders= Arrays.asList( new IgnoredBuilder(), new AnnotatedBuilder(this), suiteMethodBuilder(), new JUnit3Builder(), new JUnit4Builder()); } BEFORE public Runner runnerForClass(Class<?> testClass) throws Throwable { List<RunnerBuilder> builders= Arrays.asList( ignoredBuilder(), annotatedBuilder(), suiteMethodBuilder(), junit3Builder(), junit4Builder()); } protected AnnotatedBuilder annotatedBuilder() { return new AnnotatedBuilder(this); } AFTER 24
  • 25. RQ5: What is the purpose of the applied refactorings? We found three main motivations for the application of the extract method refactoring: code smell resolution, extension and backward compatibility. Extract Method Refactoring 44% 44% 12% 25 SSRG Lab – University of Alberta
  • 26. We classified 70 Inheritance-related refactorings in total What about Inheritance related refactorings? 26 SSRG Lab – University of Alberta
  • 27. RQ5: What is the purpose of the applied refactorings? We found three main motivations for the application of the extract method refactoring: code smell resolution, extension and refinement of abstraction level. 31% Inheritance Related Refactorings 20% 49% 27 SSRG Lab – University of Alberta
  • 28. Bird's-eye-view Conclusions RQ1: Do software developers perform different types of refactoring operations on test code and production code? In production code: Design improvements such as, resolution of code smells and modularization. In test code: Internal reorganization of the classes of each project into packages and renaming of classes for conceptual reasons. RQ2. Which developers are responsible for refactorings? Refactorings were mainly fulfilled by a single developer acting as a refactoring manager. Managers share refactoring responsibilities in both production and test code. 28 SSRG Lab – University of Alberta
  • 29. Bird's-eye-view Conclusions RQ3. Is there more refactoring activity before major project releases than after? Refactoring activity is significantly more frequent before a release than after. We believe this activity is motivated by the desire to improve the design, and prepare the code for future extensions, right before releasing a stable API. RQ4: Is refactoring activity on production code preceded by the addition or modification of test code? A tight alignment between refactoring activities and test code updates. Testing and refactoring are dependent implying the adoption of test-driven refactoring practices in the examined projects. 29 SSRG Lab – University of Alberta
  • 30. Bird's-eye-view Conclusions RQ5: What is the purpose of the applied refactorings? Extract Method refactoring: • Code smells: The decomposition of methods was the most dominant motivation • Facilitating Extension: Introduction of Factory Methods Inheritance related refactorings: • Removal of duplicate code and the generalization of abstraction. • Decomposition of interfaces and specialization of abstraction were rarely applied practices. 30 SSRG Lab – University of Alberta
  • 31. Bird's-eye-view Conclusions RQ1: Do software developers perform different types of refactoring operations on test code and production code? RQ2. Which developers are responsible for refactorings? RQ3. Is there more refactoring activity before major project releases than after? RQ4: Is refactoring activity on production code preceded by the addition or modification of test code? RQ5: What is the purpose of the applied refactorings? tsantalis@cse.concordia.ca guana@ualberta.ca 31 SSRG Lab – University of Alberta

Editor's Notes

  1. JUNIT: 383 detected refactorings, 219 (57%) were production code refactorings, while 164 (43%) weretest code refactorings.HTTPCore, 421 (80%) were applied to production code, while 106 (20%) were applied to test codeHTTPClient, 161 (81%) where applied to production code and 37 (19%)The goal of the applied refactorings on test code was often to organize the tests into new packages, reorganize inner classes, rename some test classes by giving a more meaningful name and move methods between test classes for conceptual reasons. Conversely, the refactorings that were applied to production code, of the examined systems, were intended to improve the design of the system by modularizingthe code and removing design problems. The three most dominant refactorings on production code were Move Class, Extract Method and Rename Class followed by refactorings related to the reallocation of system&apos;s behavior (Move and Pull Up Method). The refactorings related to the reallocation of system&apos;s state (Move andPull Up Field) as well as the introduction of additional inheritance levels (Extract Superclass/Interface) are less frequent. Finally, the refactorings that move state or behavior to subclasses (Push Down Method/Field) are rarely applied.
  2. JUNIT: 383 detected refactorings, 219 (57%) were production code refactorings, while 164 (43%) weretest code refactorings.HTTPCore, 421 (80%) were applied to production code, while 106 (20%) were applied to test codeHTTPClient, 161 (81%) where applied to production code and 37 (19%)The goal of the applied refactorings on test code was often to organize the tests into new packages, reorganize inner classes, rename some test classes by giving a more meaningful name and move methods between test classes for conceptual reasons. Conversely, the refactorings that were applied to production code, of the examined systems, were intended to improve the design of the system by modularizingthe code and removing design problems. The three most dominant refactorings on production code were Move Class, Extract Method and Rename Class followed by refactorings related to the reallocation of system&apos;s behavior (Move and Pull Up Method). The refactorings related to the reallocation of system&apos;s state (Move andPull Up Field) as well as the introduction of additional inheritance levels (Extract Superclass/Interface) are less frequent. Finally, the refactorings that move state or behavior to subclasses (Push Down Method/Field) are rarely applied.
  3. It is worth noticing that although HTTPCore (with 8 committers) and HTTPClient (with 9 committers) share almost the sameteam of developers, only Oleg Kalnichevski contributes refactorings in both projects. This means that the rest of the developers, althoughthey commit code in both projects, they contribute refactorings in only one of them (probably the project they are more familiar with).We can conclude that most of the applied refactorings are performed by specific developers that usually have a key role in the management of the project.Moreover, we did not notice any substantial change in the distribution of the refactoring commits by the developers to the product codeand test code of the three projects under study.
  4. It is worth noticing that although HTTPCore (with 8 committers) and HTTPClient (with 9 committers) share almost the sameteam of developers, only Oleg Kalnichevski contributes refactorings in both projects. This means that the rest of the developers, althoughthey commit code in both projects, they contribute refactorings in only one of them (probably the project they are more familiar with).We can conclude that most of the applied refactorings are performed by specific developers that usually have a key role in the management of the project.Moreover, we did not notice any substantial change in the distribution of the refactoring commits by the developers to the product codeand test code of the three projects under study.
  5. For the 4th RQ we investigated whether the refactoring activity on production code is accompanied with the addition/modification of test code.To answer this question, we had to extract periods of test code updates.
  6. For all examined projects, we found a significantly higher refactoring activity during the test update periods compared to the activity after the end of test periods.
  7. In particular, for project HTTP-Core we found that mostrefactorings actually coincide with the end of test update periods.
  8. For the 5th RQ, our goal what to find the reasons behind the application of the detected refactorings.We applied a two-phase process. In the first phase…
  9. Our first focus was the Extract Method refactoring which is considered as the Swiss Army Knife of refactorings, since it can be used to solve many design problemssuch as removing code duplication and decomposing long/complex methods, as well as it is used in combination with other refactorings to solve more complex design problems (Feature Envy, God Class). We classified 210 Extract Method instances in total. I will now show some indicative cases from the examined projects motivating the application of Extract Method refactoring.
  10. Facilitate functionality extension: The extracted/original method contains newly added code apart from the extracted/removed one.Introduce polymorphism: The extracted method is abstract and the extracted code is moved to a subclass providing a concrete implementation for the newly introduced abstract method.
  11. The encapsulation restricts the access to other classes
  12. This was done for extension purposes, because factory methods can also return subclass instances of the returned type.