一句话:提出 Nalin,结合动态分析与神经网络分类器,自动检测 Python 程序中变量名与运行时值不一致的问题。
变量名与运行时值不一致会损害代码可理解性或导致意外行为。Nalin 将追踪值到变量名赋值的动态分析与神经网络模型结合,判断名称与值是否匹配,从而把发现此类编码问题形式化为对名称和运行时值的分类问题。作者在 106,652 个真实 Python 程序上评估,发现分类器能高准确率检测名称-值不一致;相对用户研究构建的 ground truth,警告精确率 80%、召回率 76%,并可补充现有编码问题检测技术。
Variable names are important to understand and maintain code. If a variable name and the value stored in the variable do not match, then the program suffers from a name-value inconsistency, which is due to one of two situations that developers may want to fix: Either a correct value is referred to through a misleading name, which negatively affects code understandability and maintainability, or the correct name is bound to a wrong value, which may cause unexpected runtime behavior. Finding name-value inconsistencies is hard because it requires an understanding of the meaning of names and knowledge about the values assigned to a variable at runtime. This paper presents Nalin, a technique to automatically detect name-value inconsistencies. The approach combines a dynamic analysis that tracks assignments of values to names with a neural machine learning model that predicts whether a name and a value fit together. To the best of our knowledge, this is the first work to formulate the problem of finding coding issues as a classification problem over names and runtime values. We apply Nalin to 106,652 real-world Python programs, where meaningful names are particularly important due to the absence of statically declared types. Our results show that the classifier detects name-value inconsistencies with high accuracy, that the warnings reported by Nalin have a precision of 80% and a recall of 76% w.r.t. a ground truth created in a user study, and that our approach complements existing techniques for finding coding issues.