学习自然编码惯例
Learning Natural Coding Conventions
摘要:
每个程序员都有自己的风格,从标识符命名到对象关系和设计模式。编码约定定义了一致的语法风格,从而提高了可读性和可维护性。在协作时,程序员努力遵守项目的编码约定。然而,三分之一的变更评审包含关于编码约定的反馈,这表明程序员并不总是遵循这些约定,项目成员非常关心遵守情况。不幸的是,程序员通常不知道编码约定,因为推断它们需要全局视图,一个聚合程序员做出的许多局部决策并识别对风格的紧急共识的视图。我们提出了NATURALIZE,一个框架,学习风格的代码库,并建议修改,以提高风格的一致性。NATURALIZE建立在最近将统计自然语言处理应用于源代码的工作之上。我们应用NATURALIZE来建议自然标识符名称和格式约定。我们提出了四种工具,专注于在开发和发布管理过程中确保自然代码,包括代码审查。NATURALIZE在其标识符名称的顶级建议中实现了94%的准确性,甚至可以利用10,968个开源项目的语料库跨项目传输有关约定的知识。我们使用NATURALIZE为5个开源项目生成了18个补丁:其中14个被接受。
英文摘要:
Every programmer has a characteristic style, ranging from preferences about identifier naming to preferences about object relationships and design patterns. Coding conventions define a consistent syntactic style, fostering readability and hence maintainability. When collaborating, programmers strive to obey a project's coding conventions. However, one third of reviews of changes contain feedback about coding conventions, indicating that programmers do not always follow them and that project members care deeply about adherence. Unfortunately, programmers are often unaware of coding conventions because inferring them requires a global view, one that aggregates the many local decisions programmers make and identifies emergent consensus on style. We present NATURALIZE, a framework that learns the style of a codebase, and suggests revisions to improve stylistic consistency. NATURALIZE builds on recent work in applying statistical natural language processing to source code. We apply NATURALIZE to suggest natural identifier names and formatting conventions. We present four tools focused on ensuring natural code during development and release management, including code review. NATURALIZE achieves 94% accuracy in its top suggestions for identifier names and can even transfer knowledge about conventions across projects, leveraging a corpus of 10,968 open source projects. We used NATURALIZE to generate 18 patches for 5 open source projects: 14 were accepted.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。