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 <b>CUP<inline-formula><tex-math notation="LaTeX">$^\mathrm{2}$</tex-math><alternatives><mml:math xmlns:mml="http://www.w3.org/1998/Math/MathML"><mml:msup><mml:mrow/><mml:mn>2</mml:mn></mml:msup></mml:math><inline-graphic xlink:href="xia-ieq1-3138909.gif" xmlns:xlink="http://www.w3.org/1999/xlink"/></alternatives></inline-formula></b> ( <b>Two</b> -stage <b>C</b> omment <b>UP</b> dater) to automate this task. CUP <inline-formula><tex-math notation="LaTeX">$^\mathrm{2}$</tex-math></inline-formula> consists two components, i.e., an <b>O</b> bsolete <b>C</b> omment <b>D</b> etector named <b>OCD</b> and a <b>C</b> omment <b>UP</b> dater named <b>CUP</b> , each of which relies on a distinct neural network model to perform detection (updates). Specifically, given a code change and a corresponding comment, CUP <inline-formula><tex-math notation="LaTeX">$^\mathrm{2}$</tex-math></inline-formula> 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 CUP <inline-formula><tex-math notation="LaTeX">$^\mathrm{2}$</tex-math></inline-formula> , 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) CUP <inline-formula><tex-math notation="LaTeX">$^\mathrm{2}$</tex-math></inline-formula> performs better than a rule-based baseline. Specifically, the comments generated by CUP <inline-formula><tex-math notation="LaTeX">$^\mathrm{2}$</tex-math></inline-formula> are identical to the ground truth for 41.8% of the samples that are predicted to be positive by OCD. We believe CUP <inline-formula><tex-math notation="LaTeX">$^\mathrm{2}$</tex-math></inline-formula> can help developers detect obsolete comments, better understand where and how to update obsolete comments and reduce their edits on obsolete comment updates.

Full Text
Published version (Free)

Talk to us

Join us for a 30 min session where you can share your feedback and ask us any queries you have

Schedule a call