Code comments play a crucial role in software development, as they provide programmers with practical information, allowing them to understand better the intent and semantics of the underpinning code. Nevertheless, developers tend to leave comments unchanged after updating the code, resulting in a discrepancy between the two artifacts. Such a discrepancy may trigger misunderstanding and confusion among developers, impeding various activities, including code comprehension and maintenance. Thus, it is crucial to identify if, given a code snippet, its corresponding comment is coherent and reflects well the intent behind the code. Unfortunately, existing approaches to this problem, while obtaining an encouraging performance, either rely on heavily pre-trained models, or treat input data as text, neglecting the intrinsic features contained in comments and code, including word order and synonyms. This work presents Co3D as a practical approach to the detection of code comment coherence. We pay attention to internal meaning of words and sequential order of words in text while predicting coherence in code-comment pairs. We deployed a combination of Gensim word2vec encoding and a simple recurrent neural network, a combination of Gensim word2vec encoding and an LSTM model, and CodeBERT. The experimental results show that Co3D obtains a promising prediction performance, thus outperforming well-established baselines. We conclude that depending on the context, using a simple architecture can introduce a satisfying prediction.
翻译:代码注释在软件开发中扮演着关键角色,它们为程序员提供实用信息,使其能更好地理解底层代码的意图与语义。然而,开发者往往在更新代码后未同步修改注释,导致代码与注释之间出现不一致。这种不一致可能引发开发者之间的误解与困惑,阻碍包括代码理解与维护在内的多项活动。因此,对于给定代码片段,判断其对应注释是否一致并准确反映代码意图至关重要。遗憾的是,现有解决该问题的方法虽取得了令人鼓舞的性能,但要么依赖大量预训练模型,要么将输入数据视为普通文本,忽略了注释与代码中包含的词序、同义词等内在特征。本研究提出Co3D作为一种检测代码注释一致性的实用方法。我们在预测代码-注释对的一致性时,重点关注文本中词语的内在含义与顺序特征。我们部署了Gensim word2vec编码与简单循环神经网络的组合、Gensim word2vec编码与LSTM模型的组合以及CodeBERT进行实验。结果表明,Co3D取得了优异的预测性能,超越了现有基准方法。我们得出结论:根据具体情境,采用简洁的架构即可实现令人满意的预测效果。