Publication Type

Journal Article

Version

acceptedVersion

Publication Date

1-2023

Abstract

Comments are valuable resources for the development, comprehension and maintenance of software. However, while changing code, developers sometimes neglect the evolution of the corresponding comments, resulting in obsolete comments. Such obsolete comments can mislead developers and introduce bugs in the future, and are therefore detrimental. We notice that by detecting and updating obsolete comments in time with code changes, obsolete comments can be effectively reduced and even avoided. We refer to this task as Just-In-Time (JIT) Obsolete Comment Detection and Update. In this work, we propose a two-stage framework named CUP2 (Two-stage Comment UPdater) to automate this task. CUP2 consists two components, i.e., an Obsolete Comment Detector named OCD and a Comment UPdater named CUP, each of which relies on a distinct neural network model to perform detection (updates). Specifically, given a code change and a corresponding comment, CUP2 first leverages OCD to predict whether this comment should be updated. If the answer is yes, CUP will be used to generate the new version of the comment automatically. To evaluate CUP2 , we build a large-scale dataset with over 4 million code-comment change samples. Our dataset focuses on method-level code changes and updates on method header comments considering the importance and widespread use of such comments. Evaluation results show that 1) both OCD and CUP outperform their baselines by significant margins, and 2) CUP2 performs better than a rule-based baseline. Specifically, the comments generated by CUP2 are identical to the ground truth for 41.8% of the samples that are predicted to be positive by OCD. We believe CUP2 can help developers detect obsolete comments, better understand where and how to update obsolete comments and reduce their edits on obsolete comment updates.

Keywords

Code-comment co-evolution, comment update, obsolete comment detection

Discipline

Software Engineering

Research Areas

Software and Cyber-Physical Systems

Publication

IEEE Transactions on Software Engineering

Volume

49

Issue

1

First Page

1

Last Page

23

ISSN

0098-5589

Identifier

10.1109/TSE.2021.3138909

Publisher

Institute of Electrical and Electronics Engineers

Copyright Owner and License

Authors

Additional URL

https://doi.org/10.1109/TSE.2021.3138909

Share

COinS