一句话:通过大规模实证构建 Stack Overflow 代码示例适配分类体系,并实现辅助开发者交互式复用示例的 Chrome 工具。
开发者复用 Stack Overflow 代码示例时,常需按本地程序上下文适配,且不同开发者反复独立完成。本文结合克隆检测、时间戳与 URL 引用,将 SO 帖子关联到 GitHub 对应代码,构建大规模数据集;定性检查 400 个示例后归纳出 24 种适配类型。作者基于 GumTree 实现自动适配分类,并开发 Chrome 扩展 ExampleStack,从示例及对应版本中提取适配感知模板以定位高频修改热点。十六名程序员的用户研究显示,展示相似 GitHub 版本中的共性与变异能提升其复用信心,帮助全面理解不同复用方式并规避常见陷阱。
Developers often resort to online Q&A forums such as Stack Overflow (SO) for filling their programming needs. Although code examples on those forums are good starting points, they are often incomplete and inadequate for developers' local program contexts; adaptation of those examples is necessary to integrate them to production code. As a consequence, the process of adapting online code examples is done over and over again, by multiple developers independently. Our work extensively studies these adaptations and variations, serving as the basis for a tool that helps integrate these online code examples in a target context in an interactive manner. We perform a large-scale empirical study about the nature and extent of adaptations and variations of SO snippets. We construct a comprehensive dataset linking SO posts to GitHub counterparts based on clone detection, time stamp analysis, and explicit URL references. We then qualitatively inspect 400 SO examples and their GitHub counterparts and develop a taxonomy of 24 adaptation types. Using this taxonomy, we build an automated adaptation analysis technique on top of GumTree to classify the entire dataset into these types. We build a Chrome extension called ExampleStack that automatically lifts an adaptation-aware template from each SO example and its GitHub counterparts to identify hot spots where most changes happen. A user study with sixteen programmers shows that seeing the commonalities and variations in similar GitHub counterparts increases their confidence about the given SO example, and helps them grasp a more comprehensive view about how to reuse the example differently and avoid common pitfalls.