Granularity affects refactoring detection in software development

An Empirical Study on the Impact of Change Granularity in Refactoring Detection

Software Engineering

Summary

It can be hard to spot certain code improvements called refactorings if we only look at changes one commit at a time. The authors studied many Java projects and found some refactorings happen across multiple commits, while others occur briefly within a single commit. These larger or shorter refactorings have different characteristics and causes. About one-fifth of commit notes hint when big refactorings happen. The authors suggest paying more attention to these types when tracking code changes.

What this means in practice

  • For software development teams: Improve tools for detecting code improvements by considering changes spread across multiple commits, enhancing code review and comprehension.
  • For version control tool developers: Enhance refactoring detection features within version control systems by integrating methods that recognize coarse-grained and ephemeral refactorings.

Authors

Lei Chen, Shinpei Hayashi

Abstract

Detecting refactorings in commit history is essential to improve comprehension to code changes on code reviews, and to provide valuable information for empirical studies on software evolution. Techniques have been proposed to accurately detect refactorings on the granularity of a single commit. However, refactorings can be made over multiple commits because of their complexity or other practical development problems, which cause detecting on only the granularity of a single commit not enough. We observe that some refactorings can only be detected in coarser granularity, i.e., changes conducted over multiple commits, or in the granularity of a single commit but not in coarse-grained. We call these types of refactorings as coarse-grained refactorings (CGRs) and ephemeral refactorings (EPRs). We investigated the features and causes of CGRs and EPRs through an empirical study of 32 open-source Java projects and found that both commonly occur during development. In addition, we found that refactoring types related to splitting or merging classes and packages, as well as those involving modifications to the inheritance structure, tend to be CGRs, and types targeting small objects such as variables and attributes, and refactorings with context-sensitive detection criteria tend to be EPRs. The causes of CGRs and EPRs are analyzed and categorized, and the relationships between the commit messages of CGRs and themselves are also assessed. We found that about 20% of commit messages explicitly suggest the existence of CGRs. We suggest that CGRs and EPRs be valued in refactoring research and that detectors be extended to identify CGRs.