这篇论文告诉你:给代码自动取名时,先写摘要再命名比直接硬猜更靠谱。他们用DeepSeek做评估,效果比传统指标好十倍。
本研究针对方法名预测(MNP)任务,发现现有评估多依赖token相似度指标(如BLEU)与人类判断不一致,且LLM直接代码-名称映射不及人类先理解再命名的过程。实验对比6种指标评估器、5种LLM评估器(包括DeepSeek)和6名人类评估者,显示DeepSeek评估器与人类判断更一致。进一步比较直接生成与摘要-精炼策略,后者提升了语义质量。基于此提出SMNP方法,融合MNP导向摘要和链式精炼,在5个LLM和2个数据集上验证了有效性。
Understanding before Naming! Enhancing LLM-based Method Name Prediction with Code Summarization
Method names are critical to software quality, affecting code comprehensibility, maintainability, and developer collaboration. However, manually designing meaningful method names is challenging. Method Name Prediction (MNP), which automatically generates method names from code snippets, has recently attracted attention. Although large language models (LLMs) show promising performance for MNP, two challenges remain. First, existing evaluations mainly rely on token similarity metrics, which often fail to reflect human judgments of semantic quality. Second, current LLM-based MNP methods usually generate names through direct code-to-name mapping, which differs from the human process of understanding functionality before naming. To address these challenges, we conduct empirical studies on LLM-based evaluation and MNP strategies. We compare 6 metric-based evaluators, 5 LLM-based evaluators, and 6 human evaluators. Results show that LLM-based evaluators, especially DeepSeek-based evaluators, are more consistent with human judgments than traditional metrics. We further compare direct generation and summarization-and-refinement strategies. Results indicate that summarization and refinement generally improve the semantic quality of generated names. Case studies reveal three limitations: inaccurate summaries, semantic misalignment, and close semantic scores. Based on these findings, we propose SMNP, an MNP approach combining MNP-oriented summarization and chain-of-thought enhanced refinement. Experiments on 5 LLMs and 2 datasets demonstrate the effectiveness and robustness of SMNP.