Skip to main content
QUICK REVIEW

[Paper Review] Why Developers Refactor Source Code: A Mining-based Study

Jevgenija Pantiuchina, Fiorella Zampetti|arXiv (Cornell University)|Jan 5, 2021
Software Engineering ResearchComputer Science64 references16 citations
TL;DR

This study investigates why developers refactor source code through a large-scale mixed-methods analysis of 287,813 refactoring operations across 150 open-source Java projects. By combining quantitative mining of code and process metrics with qualitative analysis of 551 pull requests, the authors identify 67 distinct motivations for refactoring, revealing that semantic metrics and non-functional trade-offs significantly influence developer decisions, and highlight gaps in current refactoring recommenders and tooling.

ABSTRACT

Refactoring aims at improving code non-functional attributes without modifying its external behavior. Previous studies investigated the motivations behind refactoring by surveying developers. With the aim of generalizing and complementing their findings, we present a large-scale study quantitatively and qualitatively investigating why developers perform refactoring in open source projects. First, we mine 287,813 refactoring operations performed in the history of 150 systems. Using this dataset, we investigate the interplay between refactoring operations and process (e.g., previous changes/fixes) and product (e.g., quality metrics) metrics. Then, we manually analyze 551 merged pull requests implementing refactoring operations and classify the motivations behind the implemented refactorings (e.g., removal of code duplication). Our results led to (i) quantitative evidence of the relationship existing between certain process/product metrics and refactoring operations and (ii) a detailed taxonomy, generalizing and complementing the ones existing in the literature, of motivations pushing developers to refactor source code.

Motivation & Objective

  • To understand the real-world motivations behind software refactoring beyond survey-based assumptions.
  • To identify which product and process metrics correlate with refactoring operations in open-source systems.
  • To develop a comprehensive, empirically grounded taxonomy of refactoring motivations from actual development practices.
  • To assess the limitations of current refactoring recommenders that rely solely on structural or quality metrics.
  • To inform the design of future tools and recommendation systems that account for diverse, context-sensitive developer goals.

Proposed method

  • Mining the version history of 150 open-source Java projects hosted on GitHub using the RMiner tool to extract 287,813 refactoring operations across 25 types.
  • Analyzing relationships between refactoring operations and product metrics (e.g., code quality, readability, C3) and process metrics (e.g., fault-proneness, change frequency).
  • Selecting a statistically significant sample of 551 pull requests containing refactoring changes for manual analysis.
  • Conducting qualitative coding of pull request discussions and commit messages to classify the rationale and intent behind each refactoring.
  • Building a taxonomy of 67 motivations by synthesizing findings from manual analysis, generalizing and extending prior survey-based taxonomies.
  • Comparing quantitative metric correlations with qualitative motivations to assess the limitations of metric-driven refactoring recommendation systems.

Experimental results

Research questions

  • RQ1Which product and process metrics are most strongly correlated with refactoring operations in real-world software projects?
  • RQ2What are the primary motivations driving developers to perform refactoring, as derived from actual pull request discussions and code changes?
  • RQ3How do the motivations identified in this study compare to or extend those found in prior survey-based research?
  • RQ4To what extent do current refactoring recommenders, based on code quality metrics, capture the full spectrum of developer-driven refactoring motivations?
  • RQ5What are the key gaps in existing tools and practices that prevent the automation of common, manually performed refactorings?

Key findings

  • Semantic metrics—particularly readability and C3 (Conceptual Cohesion of Classes)—showed the strongest quantitative correlation with refactoring operations, suggesting developers prioritize code understandability.
  • The most frequently cited motivations for refactoring include removing code duplication, improving readability, and fixing code smells, with 67 distinct motivations identified in the qualitative analysis.
  • Many refactoring operations were driven by code review feedback, especially for naming improvements and abbreviation expansion, indicating that peer review is a major catalyst for change.
  • A significant number of refactorings were preemptive or aimed at accommodating future changes, highlighting a strategic, forward-looking dimension often missed by current recommenders.
  • Current refactoring recommenders that rely on structural or quality metrics alone are likely to miss many meaningful refactorings, especially those driven by semantic or maintainability trade-offs.
  • The study identifies key automation opportunities, such as automatic abbreviation expansion and detection of redundant code, which remain unsupported by production-ready tools despite existing research solutions.

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.