一句话:提出工具 EG,通过挖掘代码库自动生成简洁、具代表性的 API 惯用示例,并集成到 Facebook 代码搜索中。
现代软件开发中,程序员常需借助文档和代码搜索来回忆 API 的正确用法,但高质量 API 示例的整理与维护成本很高,而从公司级代码搜索中检索到的示例又往往冗长、难以快速审阅。本文提出工具 EG,它通过挖掘代码库,为 API 方法自动找出常见且惯用的使用示例。EG 被集成到 Facebook 内部面向 Hack 语言的代码搜索工具中,并在 Python 开源项目上进行了评估。作者还将 EG 与代码搜索结果以及知名编程网站 ProgramCreek 上的手写示例进行对比。结果显示,EG 生成的示例更加简洁、更具代表性,包含的多余语句更少;此外,一项面向 Facebook 开发者的调查表明,在 97% 的情况下开发者更偏好 EG 生成的示例。
Modern software engineering often involves using many existing APIs, both open source and – in industrial coding environments– proprietary. Programmers reference documentation and code search tools to remind themselves of proper common usage patterns of APIs. However, high-quality API usage examples are computationally expensive to curate and maintain, and API usage examples retrieved from company-wide code search can be tedious to review. We present a tool, EG, that mines codebases and shows the common, idiomatic us-age examples for API methods. EG was integrated into Facebook’s internal code search tool for the Hack language and evaluated on open-source GitHub projects written in Python. EG was also compared against code search results and hand-written examples from a popular programming website called ProgramCreek. Compared with these two baselines, examples generated by EG are more succinct and representative with less extraneous statements. In addition, a survey with Facebook developers shows that EG examples are preferred in 97% of cases.