Abstract
Misleading method names in software projects can confuse developers, leading to software defects and reduced code understandability. We present DeepName, a context-based deep learning approach designed to detect method name inconsistencies and suggest appropriate names. Following the philosophy of "Show Me Your Friends, I'll Tell You Who You Are," DeepName considers a method's interactions with callers, callees, and sibling methods in addition to its own body. Using an RNN-based encoder-decoder with a novel non-copy mechanism, DeepName achieves significant improvements over state-of-the-art tools. In real-world evaluations, 30 out of 50 suggested names were deemed more meaningful by project maintainers, with 12 suggestions merged into active open-source projects.
Introduction
In software engineering, names serve as vital documentation. A misleading name, such as a method called isReady() that actually modifies a database, creates "cognitive distance," complicating maintenance and increasing the risk of bugs. While existing tools suggest names based on a method's internal implementation, many methods are "thin"—containing very little code—making internal analysis insufficient. DeepName addresses this by leveraging the broader context of a method's "social circle" within the codebase.
Methodology: The DeepName Framework
DeepName extracts features from four distinct contexts to understand a method's purpose: internal context (body and parameters), interaction context (callers and callees), sibling context (other methods in the same class), and enclosing context (class name and fields).
Architecture and the Non-Copy Mechanism
The core of DeepName is a sequence-to-sequence (seq2seq) model using Gated Recurrent Units (GRUs). It processes sub-tokens of program entity names to generate suggestions.
The model integrates two critical mechanisms:
- Copy Mechanism: Directly transfers relevant sub-tokens from the context into the suggested name.
- Non-copy Mechanism: This novel component calculates the likelihood that a specific sub-token should not follow another. By penalizing statistically unlikely sequences, it refines the ranking of suggested names.
For consistency checking, a two-channel CNN classifier compares the existing name's representation against the implementation and context representations.
Experimental Evaluation
DeepName was evaluated on two massive datasets: a consistency checking set of ~2.1 million methods and a name suggestion corpus of 14.4 million methods from over 10,000 GitHub Java projects.
Key Results
DeepName significantly outperformed baselines such as code2vec, code2seq, and MNire across all metrics.
- Name Suggestion: DeepName achieved an exact match rate of 44.3%, improving F-score by 5.2% to 38.2% relative to other models.
- Consistency Checking: The model improved the state-of-the-art F-score by 11.9%, reaching an overall accuracy of 75.8%.
- Real-World Impact: Out of 50 pull requests submitted to active projects, 12 were merged. In 60% of cases, maintainers preferred DeepName's suggestions over the original names.
Discussion and Future Work
DeepName demonstrates that interaction and sibling contexts are vital for naming "thin" methods. Furthermore, the "Non-copy" mechanism proves that negative constraints are as valuable as positive ones in sequence generation. While currently optimized for Java, the framework's logic is language-agnostic. Future work includes extending support to other languages and exploring project-wide global naming conventions.
Summary updated