Suboptimal code is prevalent in software systems. Developers often write low-quality code due to factors like technical knowledge gaps, insufficient experience, time pressure, management decisions, or personal factors. Once integrated, the accumulation of this suboptimal code leads to significant maintenance costs and technical debt. Developers frequently consult external knowledge bases, such as API documentation and Q&A websites like Stack Overflow (SO), to aid their programming tasks. SO's crowdsourced, collaborative nature has created a vast repository of programming knowledge. Its community-curated content is constantly evolving, with new answers posted or existing ones edited. In this paper, we present an empirical study of SO Java answer edits and their application to improving code in open-source projects. We use a modified code clone search tool to analyze SO code snippets with version history and apply it to open-source Java projects. This identifies outdated or unoptimized code and suggests improved alternatives. Analyzing 140,840 Java accepted answers from SOTorrent and 10,668 GitHub Java projects, we manually categorized SO answer edits and created pull requests to open-source projects with the suggested code improvements. Our results show that 6.91% of SO Java accepted answers have more than one revision (average of 2.82). Moreover, 49.24% of the code snippets in the answer edits are applicable to open-source projects, and 11 out of 36 proposed bug fixes based on these edits were accepted by the GitHub project maintainers.


翻译:次优代码在软件系统中普遍存在。开发者常因技术知识不足、经验欠缺、时间压力、管理决策或个人因素编写低质量代码。一旦集成,这些次优代码的积累将导致高昂的维护成本和技术债务。开发者常参考外部知识库(如API文档和Stack Overflow等问答网站)辅助编程任务。Stack Overflow的众包协作特性形成了庞大的编程知识库,其社区维护的内容持续演化,新答案不断发布,现有答案被频繁编辑。本文对Stack Overflow Java答案编辑及其在开源项目代码改进中的应用进行实证研究。我们使用改进的代码克隆搜索工具分析具有版本历史的Stack Overflow代码片段,并将其应用于开源Java项目,以识别过时或未优化的代码并提供改进建议。通过分析SOTorrent中的140,840个Java采纳答案和10,668个GitHub Java项目,我们手动分类了Stack Overflow答案编辑,并向开源项目提交包含建议代码改进的拉取请求。结果显示:6.91%的Stack Overflow Java采纳答案存在多次修订(平均2.82次);49.24%的答案编辑中的代码片段可应用于开源项目;基于这些编辑提出的36个错误修复建议中,有11个被GitHub项目维护者采纳。

0
下载
关闭预览

相关内容

代码(Code)是专知网的一个重要知识资料文档板块,旨在整理收录论文源代码、复现代码,经典工程代码等,便于用户查阅下载使用。
EMNLP 2021 | 学习改写非自回归机器翻译的翻译结果
专知会员服务
16+阅读 · 2021年12月25日
Python图像处理,366页pdf,Image Operators Image Processing in Python
NAACL 2019 | 一种考虑缓和KL消失的简单VAE训练方法
PaperWeekly
20+阅读 · 2019年4月24日
论文报告 | Graph-based Neural Multi-Document Summarization
科技创新与创业
15+阅读 · 2017年12月15日
国家自然科学基金
17+阅读 · 2017年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
4+阅读 · 2015年12月31日
国家自然科学基金
2+阅读 · 2015年12月31日
国家自然科学基金
4+阅读 · 2014年12月31日
VIP会员
相关基金
国家自然科学基金
17+阅读 · 2017年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
4+阅读 · 2015年12月31日
国家自然科学基金
2+阅读 · 2015年12月31日
国家自然科学基金
4+阅读 · 2014年12月31日
Top
微信扫码咨询专知VIP会员