Skip to main content
QUICK REVIEW

[论文解读] From Query to Usable Code: An Analysis of Stack Overflow Code Snippets

Di Yang, Aftab M. Hussain|arXiv (Cornell University)|May 14, 2016
Software Engineering Research参考文献 16被引用 54
一句话总结

本文分析了 Stack Overflow 代码片段在自动化程序生成中的可用性,评估了 C#、Java、JavaScript 和 Python 中的解析、编译和执行情况。研究发现,像 Python 和 JavaScript 这类动态类型语言的可用性显著更高(约 70% 的代码可运行),而像 C# 和 Java 这类静态类型语言的可用性则较低,因此更适合作为自动化代码合成工具的构建模块。

ABSTRACT

Enriched by natural language texts, Stack Overflow code snippets are an invaluable code-centric knowledge base of small units of source code. Besides being useful for software developers, these annotated snippets can potentially serve as the basis for automated tools that provide working code solutions to specific natural language queries. With the goal of developing automated tools with the Stack Overflow snippets and surrounding text, this paper investigates the following questions: (1) How usable are the Stack Overflow code snippets? and (2) When using text search engines for matching on the natural language questions and answers around the snippets, what percentage of the top results contain usable code snippets? A total of 3M code snippets are analyzed across four languages: C\#, Java, JavaScript, and Python. Python and JavaScript proved to be the languages for which the most code snippets are usable. Conversely, Java and C\# proved to be the languages with the lowest usability rate. Further qualitative analysis on usable Python snippets shows the characteristics of the answers that solve the original question. Finally, we use Google search to investigate the alignment of usability and the natural language annotations around code snippets, and explore how to make snippets in Stack Overflow an adequate base for future automatic program generation.

研究动机与目标

  • 评估 Stack Overflow 代码片段作为自动化程序生成构建模块的可用性。
  • 确定在主要编程语言中,有多少比例的代码片段在语法上正确、可编译或可运行。
  • 评估针对自然语言查询的 Google 搜索前几名结果是否返回来自 Stack Overflow 的可用代码片段。
  • 通过定性分析识别 Python 中高质量、可用代码片段的特征。
  • 探索使用自然语言查询检索可用代码以支持自动组合与修复的可行性。

提出的方法

  • 从 Stack Overflow 收集了 300 万个在 C#、Java、JavaScript 和 Python 四种语言中被采纳的答案代码片段。
  • 通过自动化方式执行解析、编译(针对 C# 和 Java)和执行(针对 Python 和 JavaScript),以评估代码片段的可用性。
  • 对 Java 和 C# 代码片段中的语法错误应用启发式修复技术,以提高其可编译性。
  • 对 40,000 多个可运行的 Python 代码片段进行三步定性分析,以评估其在解决原始问题时的正确性和完整性。
  • 使用 Google Web Search 获取样本查询的前几名结果,并测量其中可用代码片段的比例。
  • 将可用性定义为语法正确性、编译成功以及运行时无错误执行。

实验结果

研究问题

  • RQ1不同编程语言中,Stack Overflow 代码片段的可用性如何?
  • RQ2针对自然语言查询的 Google 搜索前几名结果中,有多少比例包含来自 Stack Overflow 的可用代码片段?
  • RQ3哪些特征能够区分 Python 中高质量、可用的代码片段?
  • RQ4启发式修复在多大程度上能提高静态类型语言中代码片段的可用性?
  • RQ5自然语言查询与 Stack Overflow 中可用代码片段之间的对齐程度,是否足以支持自动化程序生成?

主要发现

  • Python 和 JavaScript 展现出显著更高的可用性,约 70% 的代码片段可运行,而 C# 和 Java 仅有约 10%。
  • 经过启发式修复后,Java 代码片段的可编译性有所提高,但 C# 代码片段由于持续存在的语法问题,仍基本无法修复。
  • 对 40,000 多个可运行的 Python 代码片段进行定性分析发现,多行代码块在完整且正确地解决原始问题方面更为有效。
  • 针对自然语言查询的 Google 搜索前几名结果通常返回已可运行的 Stack Overflow 代码片段,表明用户查询与可执行代码之间存在较强对齐。
  • 结果表明,像 Python 和 JavaScript 这类动态类型语言由于具有更高的开箱即用可用性,更适合作为自动化代码合成的来源。
  • 尽管动态语言的可用性较高,但 C# 和 Java 代码片段可编译性低,表明在静态类型环境中进行自动化修复与组合仍面临重大挑战。

更好的研究,从现在开始

从论文设计到论文写作,大幅缩短您的研究时间。

无需绑定信用卡

本解读由 AI 生成,并经人工编辑审核。