AUTOGENICS:使用 LLM 自动生成编程问答网站上代码片段的上下文感知内联注释
AUTOGENICS: Automated Generation of Context-Aware Inline Comments for Code Snippets on Programming Q&A Sites Using LLM
AI总结:
本文提出 AUTOGENICS 工具,通过从问题文本提取上下文并去除噪声,利用 LLM 为 Stack Overflow 代码片段生成上下文感知的内联注释,显著提升了注释的准确性、充分性、简洁性和有用性。
摘要:
源代码中的内联注释有助于轻松理解、重用和提高可读性。然而,像 Stack Overflow (SO) 这样的问答网站上的代码片段通常缺乏注释,因为回答者是自愿贡献时间的,并且由于时间限制经常跳过注释或解释。现有研究表明,这些在线代码示例难以阅读和理解,使得开发者(尤其是新手)难以正确使用它们,从而导致误用。鉴于这些挑战,我们引入了 AUTOGENICS,这是一个旨在与 SO 集成、利用大型语言模型 (LLMs) 为 SO 回答中的代码片段生成有效内联注释的工具。我们的贡献有三个方面。首先,我们从 SO 中随机选择 400 个回答代码片段,并使用 LLMs 为它们生成内联注释。然后,我们使用四个关键指标:准确性、充分性、简洁性和有用性,手动评估这些注释的有效性。总体而言,LLMs 在为 SO 回答代码片段生成内联注释方面展现出令人满意的有效性。其次,我们调查了 14 名活跃的 SO 用户,以了解他们对这些内联注释有效性的看法。调查结果与我们之前的手动评估一致。然而,根据我们的评估,LLMs 生成的注释对较短的代码片段效果较差,并且有时会产生嘈杂的注释。第三,为了弥补这些差距,我们引入了 AUTOGENICS,它从问题文本中提取额外的上下文,并生成上下文感知的内联注释。它还通过去除噪声(例如,import 语句和变量声明中的注释)来优化注释。我们使用相同的四个指标评估了 AUTOGENICS 生成的注释的有效性,其表现优于标准 LLMs。AUTOGENICS 可能会 (a) 增强代码理解,(b) 节省时间,并提高开发者更准确地学习和重用代码的能力。
英文摘要:
Inline comments in the source code facilitate easy comprehension, reusability, and enhanced readability. However, code snippets in answers on Q&A sites like Stack Overflow (SO) often lack comments because answerers volunteer their time and often skip comments or explanations due to time constraints. Existing studies show that these online code examples are difficult to read and understand, making it difficult for developers (especially novices) to use them correctly and leading to misuse. Given these challenges, we introduced AUTOGENICS, a tool designed to integrate with SO to generate effective inline comments for code snippets in SO answers exploiting large language models (LLMs). Our contributions are threefold. First, we randomly select 400 answer code snippets from SO and generate inline comments for them using LLMs. We then manually evaluate these comments' effectiveness using four key metrics: accuracy, adequacy, conciseness, and usefulness. Overall, LLMs demonstrate promising effectiveness in generating inline comments for SO answer code snippets. Second, we surveyed 14 active SO users to perceive the effectiveness of these inline comments. The survey results are consistent with our previous manual evaluation. However, according to our evaluation, LLMs-generated comments are less effective for shorter code snippets and sometimes produce noisy comments. Third, to address the gaps, we introduced AUTOGENICS, which extracts additional context from question texts and generates context-aware inline comments. It also optimizes comments by removing noise (e.g., comments in import statements and variable declarations). We evaluate the effectiveness of AUTOGENICS-generated comments using the same four metrics that outperform those of standard LLMs. AUTOGENICS might (a) enhance code comprehension, (b) save time, and improve developers' ability to learn and reuse code more accurately.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。