函数名称质量的高低,对于理解和维护程序非常重要.然而对于软件开发人员,尤其是母语非英语的软件开发人员,为函数选取高质量的名称比较困难.为此,提出一种函数名称推荐方法.首先,基于开塬软件创建函数库:然后,对于某个需要推荐名称的函数工从函数库中检索与其相似的函数.对检索返回的相似函数用自然语言处理工具对函数名进行解析并获取标注词条,然后,从相应的函数体中提取特征代码并与相应的标注词条建立关联.基于此关联关系以及函数厂的特征,自动推荐合适的函数名.该方法在开源项的l430个函数中进行了初步验证,结果表明:有22.7%的推荐结果与原函数名完全一致,有57.9%的推荐结果与原函数名关键词一致或基本一致。
Quality of method names is critical for the readability and maintainability of program. However, it is difficult for software engineers, especially non-English speaking, inexperienced engineers, to propose high quality method names. To address this issue, this paper proposes an approach to recommend method names. First, a method corpus is constructed from open source applications. For a given method f to be named, similar methods are retrieved from the method corpus. Names of these retrieved methods are divided into phrases, and features of these methods are extracted as well. A mapping between these phrases and features is also created to derive a list of candidate phrases and features for the method to be named. These phrases are finally constructed into candidate method names. The proposed approach is evaluated on 1 430 methods in open source applications. Evaluation results suggest that 22.7 percent of recommended method names are the same as original ones, and 57.9 percent has the same or almost the same keywords as original ones.