How Are We Detecting Inconsistent Method Names? An Empirical Study from Code Review Perspective

Kisub Kim, Xin Zhou, Dongsun Kim, Julia Lawall, Kui Liu, Tegawendé F. Bissyandé, Jacques Klein, Jaekwon Lee, David Lo

TL;DR

This paper introduces RENAME4J, a novel benchmark of method name changes derived from real code reviews, to better evaluate tools that detect and recommend method names. Their empirical study reveals that current state-of-the-art tools underperform on this review-driven benchmark, highlighting a gap between research and practice and suggesting a need for more context-aware evaluation.

What Problem Does This Paper Address?

Choosing clear and consistent method names is crucial for software maintainability and comprehension. However, developers often struggle with this, leading to inconsistent naming. While many tools have been developed to automatically check for and recommend method names, their evaluation has often relied on datasets that lack the crucial context of why a name change was made. Existing datasets might only show a name change without reviewer feedback, making it hard to discern if the change reflects community conventions or a single developer's opinion. This paper aims to bridge this gap by using code reviews to create a more realistic and insightful benchmark for evaluating these tools.

Methods

The core of this research is the creation of a new benchmark called RENAME4J. This benchmark is built by mining GitHub pull requests, specifically focusing on those with discussions related to method naming. The authors manually curated pairs of "buggy" (original) and "fixed" (renamed) method names, along with their corresponding method bodies and the actual review comments that justified the change.

To evaluate existing tools, they selected three state-of-the-art techniques: Spot, Cognac, and GTNM. These tools were then tested on two primary tasks:

  1. Method Name Recommendation (MNR): Predicting a correct method name given its body.
  2. Method Name Consistency Checking (MCC): Determining if a given method name is consistent with its body.

The study also explores the impact of imbalanced datasets (reflecting real-world scenarios where consistent names are far more common than inconsistent ones) on tool performance.

Datasets

  • Java-large dataset: Used for training and validation of the recommendation-based techniques (Cognac and GTNM). This is a large, popular dataset comprising over 14 million methods from 10,000+ Java projects.
  • Spot's original training dataset: Used for training Spot due to its known scalability issues with larger datasets.
  • RENAME4J: The novel benchmark introduced in this paper. It contains 400 manually verified pairs of method names (buggy and fixed), method bodies, and corresponding review comments. This dataset is specifically designed to provide the rationale behind name changes.
  • Imbalanced dataset: A dataset derived from RENAME4J and other stable methods, reflecting the real-world imbalance between consistent and inconsistent method names.

Key Insights and Ideas

  • Code reviews are a goldmine for understanding naming rationale: The explicit discussions in code reviews provide invaluable context that is missing from many existing datasets, making them a more robust source for evaluating naming tools.
  • Current tools struggle with review-driven context: State-of-the-art tools, when evaluated on RENAME4J, show a significant drop in performance compared to their original evaluations. This suggests they may not be effectively leveraging the rich semantic and contextual information present in code reviews.
  • Descriptive names are preferred in practice: RENAME4J contains method names that are significantly longer and more descriptive than those in existing datasets, indicating that real-world developers and reviewers value explicitness.
  • Imbalanced data reveals hidden biases: Testing tools on imbalanced datasets highlights their tendency to overclassify consistent names as inconsistent, a critical flaw for real-world applicability.
  • Evaluation protocols need refinement: The study points out potential biases in existing evaluation methods, particularly for MCC, and suggests a need for more careful consideration of how "true positives" are defined.

Key Results

  • MNR Performance Drop: All three target techniques (Spot, Cognac, GTNM) showed lower performance on RENAME4J compared to their original reported results. For example, Cognac's F1-score for MNR dropped from 66.30% to 30.49%.
  • MCC Performance Drop: Similar to MNR, MCC performance also decreased significantly. For instance, Spot's F1-score for the 'C' (consistent) class dropped from 49.90% to 9.26%.
  • Imbalanced Data Impact: On the imbalanced dataset, techniques were highly biased towards classifying pairs as inconsistent. Precision for the 'C' class dropped dramatically for all techniques (e.g., Spot from 62.50% to 9.89%).
  • Descriptive Names: Method names in RENAME4J were, on average, 88.92% longer than those in existing datasets, with more split sub-tokens, indicating a preference for descriptive naming.

Limitations and Future Work

  • Benchmark Size: While RENAME4J is valuable, the number of test oracles (400 pairs) is relatively small compared to some existing datasets. The authors plan to continuously extend this benchmark.
  • Language Specificity: The study focuses on Java projects, so conclusions may not directly generalize to other programming languages.
  • Training Data Bias: The use of a common large-scale dataset for training recommendation models might introduce biases, although the authors attempted to mitigate this by using a high-quality, well-maintained dataset.
  • Future Work: The authors suggest exploring more advanced evaluation methods, developing strategies to construct improved benchmarks with minimal manual effort, and further investigating how to leverage review context to improve tool performance. They also highlight the need for more robust evaluation protocols that account for dataset imbalances and potential biases.

Summary updated

BibTeX
@article{kim2023how,
  author = {Kisub Kim and Xin Zhou and Dongsun Kim and Julia Lawall and Kui Liu and Tegawendé F. Bissyandé and Jacques Klein and Jaekwon Lee and David Lo},
  title = {{How Are We Detecting Inconsistent Method Names? An Empirical Study from Code Review Perspective}},
  journal = {ACM Trans. Softw. Eng. Methodol.},
  year = {2023},
}
Figure