Question-and-answer platforms such as Stack Overflow are an important way for software developers to share and retrieve knowledge. However, reusing poorly understood code can lead to serious problems, such as bugs or security vulnerabilities. To better understand how code comments affect the perceived helpfulness of Stack Overflow answers, we conducted an online experiment simulating a Stack Overflow environment (n=91). The results indicate that both block and inline comments are perceived as significantly more helpful than uncommented source code. Moreover, novices rated code snippets with block comments as more helpful than those with inline comments. Interestingly, other surface features, such as the position of an answer and its answer score, were considered less important. Moreover, the content of Stack Overflow has been a major source for training large language models. AI-based coding assistants such as GitHub Copilot, which are based on these models, are changing the way Stack Overflow is used. However, our findings have implications beyond Stack Overflow. First, they may help to improve the relevance also of other community-driven platforms, which provide human advice and explanations of code solutions, complementing AI-based support for software developers. Second, since chat-based AI tools can be prompted to generate code in different ways, knowing which properties influence perceived helpfulness can lead to more targeted prompting strategies to generate readable code snippets.
翻译:问答平台(如Stack Overflow)是软件开发者分享和获取知识的重要途径。然而,复用理解不足的代码可能导致严重问题,如程序错误或安全漏洞。为深入理解代码注释如何影响Stack Overflow回答的感知有用性,我们开展了一项模拟Stack Overflow环境的在线实验(n=91)。结果表明,无论是块注释还是行内注释,其感知有用性均显著高于未注释的源代码。此外,新手认为带有块注释的代码片段比带有行内注释的更具帮助性。有趣的是,其他表面特征(如回答的排序位置及评分)则被认为相对次要。值得关注的是,Stack Overflow的内容已成为训练大语言模型的主要来源。基于这些模型的AI编程助手(如GitHub Copilot)正改变着Stack Overflow的使用方式。然而,我们的发现远不止影响Stack Overflow本身:首先,这有助于提升其他社区驱动平台的相关性——这些平台提供人工建议和代码解决方案解释,可补充基于AI的开发者支持工具;其次,由于基于聊天的AI工具可通过不同提示方式生成代码,了解影响感知有用性的属性,将有助于制定更精准的提示策略,以生成可读性强的代码片段。