[Paper Review] A Context-based Automated Approach for Method Name Consistency Checking and Suggestion
This paper proposes DeepName, a context-aware deep learning approach that improves method name consistency checking and suggestion by leveraging interactions with callers, callees, siblings, and enclosing classes. By using RNN-based encoding with sub-token sequences and novel copy/non-copy mechanisms, DeepName achieves state-of-the-art performance, improving precision, recall, and F-score by up to 38.2% in name suggestion and 19.6% in consistency checking on large-scale datasets with over 14 million methods.
Misleading method names in software projects can confuse developers, which may lead to software defects and affect code understandability. In this paper, we present DeepName, a context-based, deep learning approach to detect method name inconsistencies and suggest a proper name for a method. The key departure point is the philosophy of "Show Me Your Friends, I'll Tell You Who You Are". Unlike the state-of-the-art approaches, in addition to the method's body, we also consider the interactions of the current method under study with the other ones including the caller and callee methods, and the sibling methods in the same enclosing class. The sequences of sub-tokens in the program entities' names in the contexts are extracted and used as the input for an RNN-based encoder-decoder to produce the representations for the current method. We modify that RNN model to integrate the copy mechanism and our newly developed component, called the non-copy mechanism, to emphasize on the possibility of a certain sub-token not to be copied to follow the current sub-token in the currently generated method name. We conducted several experiments to evaluate DeepName on large datasets with +14M methods. For consistency checking, DeepName improves the state-of-the-art approach by 2.1%, 19.6%, and 11.9% relatively in recall, precision, and F-score, respectively. For name suggestion, DeepName improves relatively over the state-of-the-art approaches in precision (1.8%--30.5%), recall (8.8%--46.1%), and F-score (5.2%--38.2%). To assess DeepName's usefulness, we detected inconsistent methods and suggested new method names in active projects. Among 50 pull requests, 12 were merged into the main branch. In total, in 30/50 cases, the team members agree that our suggested method names are more meaningful than the current names.
Motivation & Objective
- To address the problem of inconsistent or misleading method names that hinder code understandability and lead to software defects.
- To improve method name suggestion beyond relying solely on method bodies by incorporating contextual information from callers, callees, siblings, and enclosing classes.
- To develop a deep learning model that can generate novel, meaningful method names not present in training data, overcoming limitations of retrieval-based approaches.
- To evaluate the practical usefulness of suggested names in real-world software projects through integration into active development workflows.
Proposed method
- DeepName extracts sub-token sequences from program entities in four contexts: internal body, callers/callees, siblings, and enclosing class.
- It uses an RNN-based encoder-decoder architecture to combine contextual representations into a unified vector for the target method.
- The model incorporates a copy mechanism to retain relevant sub-tokens from context and a novel non-copy mechanism to suppress irrelevant sub-tokens during name generation.
- Sub-tokens from method names, parameters, and return types are used as input features instead of AST or PDG structures, based on their superior performance in prior work.
- A convolutional layer is applied to the final representation to classify whether a given method name is consistent with its context.
- The approach is trained end-to-end on a large dataset of 14+ million methods, with fine-tuning for both consistency checking and name suggestion tasks.
Experimental results
Research questions
- RQ1Can incorporating contextual information from callers, callees, siblings, and enclosing classes improve method name consistency checking beyond relying on method bodies alone?
- RQ2How effective is a deep learning model with sub-token-level attention and copy/non-copy mechanisms in generating meaningful, novel method names?
- RQ3To what extent does DeepName outperform existing state-of-the-art approaches in precision, recall, and F-score for method name suggestion and inconsistency detection?
- RQ4How useful are the suggested method names in real-world software development settings, as judged by human developers?
Key findings
- DeepName improves the state-of-the-art approach by 2.1% relatively in recall, 19.6% in precision, and 11.9% in F-score for method name consistency checking.
- For method name suggestion, DeepName achieves relative improvements of 1.8% to 30.5% in precision, 8.8% to 46.1% in recall, and 5.2% to 38.2% in F-score over existing methods.
- In real-world evaluation, 30 out of 50 suggested method names were judged by team members as more meaningful than the original names, with 12 pull requests successfully merged into main branches.
- The model demonstrates strong generalization by generating previously unseen method names, indicating effective zero-shot generalization beyond training data.
- The non-copy mechanism significantly enhances name quality by reducing the likelihood of copying irrelevant sub-tokens during generation.
- DeepName outperforms IR-based approaches by generating novel, contextually appropriate names not constrained to existing names in the training set.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.