一句话:提出基于数据挖掘与启发式的方法,自动判断源代码中的缩写是否应展开为完整术语。
本文研究源代码中缩写是否应展开为全称。不当缩写会降低可读性与可维护性,但已有工作多是为缩写推荐全称,缺少自动判断是否应展开的方法。作者提出开发者辅助方法:从程序语料挖掘相似上下文中广泛使用的常见缩写,并将挖掘问题转化为最大团问题;统计变量名、方法名等标识符长度的概率分布;检查缩写全称是否已出现在同一源代码行上下文中。若缩写匹配常见缩写、展开会降低所属标识符长度概率,或全称已在周围上下文出现,则建议不展开;其余缩写预期应替换为全称。在五个开源应用的 1,818 个缩写上评估,准确率达 95%。
Abbreviations are common in source code. Properly designed abbreviations may significantly facilitate typing, typesetting, and reading of lengthy source code. However, abbreviations, if used improperly, may also significantly reduce the readability and maintainability of source code. Although a few automated approaches have been proposed to suggest full terms for given abbreviations, to the best of our knowledge, there is no automated approaches to suggest whether abbreviations are used properly, i.e., whether they should be replaced with corresponding full terms. Notably, it is often challenging for inexperienced developers and maintainers to make such decisions. To this end, in this paper, we propose an automated approach to assisting developers and maintainers in making the decisions. The rationale of the approach is that abbreviations should not be expanded if the expansion would result in unacceptably lengthy identifiers or if developers/maintainers can easily figure out the meaning (full terms) of the abbreviations based on their domain knowledge or contexts of the abbreviations. From a corpus of programs, we leverage data mining techniques to discover common abbreviations that are frequently employed by various developers in similar contexts. The key of the data mining is to turn the problem of mining common abbreviations into the maximal clique problem that has been extensively studied. We suggest to not expand given abbreviation if it matches at least one of the discovered common abbreviations. From the same corpus, we also calculate the probability distribution for the length of different types of identifier, e.g., variable names and method names. The probability distribution specifies how likely an identifier of type T is composed of exactly n characters. Our heuristic is to not expand the abbreviation if the probability of its enclosing identifier would be reduced by the expansion. Finally, we also suggest to not expand the abbreviation if its full terms are contained in surrounding contexts of the abbreviation, i.e., tokens on the same source code line. Other abbreviations that do not receive suggestions from the proposed approach are expected to be replaced with their full terms. Our evaluation results on 1,818 abbreviations from five open-source applications suggest that the proposed approach is accurate with a high accuracy of 95%.