Learning natural coding conventions
By Miltiadis Allamanis, Earl T. Barr, Charles Sutton. 2014
406 citations recorded by the source corpus.
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. We used NATURALIZE to generate 18 patches for 5 open source projects: 14 were accepted.
Subfields: Computer Science Applications, Information Systems, Software, Natural Language Processing, Code Generation & Program Synthesis
How researchers see this paper
The researchers whose trusted networks rank it highest, strongest advocate first. Every researcher gets a different order.
In Computer Science Applications
- Premkumar T. Devanbu
- Michael Pradel
- Charles Sutton
- Koushik Sen
- Miltiadis Allamanis
- Earl T. Barr
- Christian Bird
- Alberto Bacchelli
In Information Systems
- Miltiadis Allamanis
- Charles Sutton
- Michael Pradel
- Premkumar T. Devanbu
- Earl T. Barr
- Eran Yahav
- Koushik Sen
- Vincent J. Hellendoorn
In Software
- Charles Sutton
- Miltiadis Allamanis
- Michael Pradel
- Premkumar T. Devanbu
- Koushik Sen
- Earl T. Barr
- Vincent J. Hellendoorn
- Rishabh Singh
In Natural Language Processing
- Charles Sutton
- Miltiadis Allamanis
- Premkumar T. Devanbu
- Michael Pradel
- Eran Yahav
- Graham Neubig
- Vincent J. Hellendoorn
- Uri Alon
In Code Generation & Program Synthesis
- Charles Sutton
- Miltiadis Allamanis
- Premkumar T. Devanbu
- Michael Pradel
- Vincent J. Hellendoorn
- Rishabh Singh
- Rafael-Michael Karampatsis
- Han Liu
Citations in the corpus
- Program Synthesis with Large Language Models (2021, methodology): “Methods aim improving code readability by asking a model trained on a code corpus with good style to predict names of variables and methods in new code [Raychev et al., 2015, Allamanis et al., 2014, Alon et al., 2019].”
- A Survey of Machine Learning for Big Code and Naturalness (2017, methodology): “They seek to prevent some classes of bugs and make code easier to comprehend, navigate, and maintain [5].”
- Unsupervised Translation of Programming Languages (2020, background): “Another line of work studied the applications of neural networks to code suggestion [2, 11, 34], or error detection [13, 18, 47].”
- Structured Generative Models of Natural Source Code (2014, background): “, 2013), as a basis for code complexity metrics (Allamanis & Sutton, 2013), and to help with enforcing coding conventions (Allamanis et al., 2014).”
- Learning to Represent Programs with Graphs (2017, methodology): “In these works, all variable usages are deterministically known beforehand (as the code is complete and remains unmodified), as in Allamanis et al. (2014; 2015).”
- code2vec: learning distributed representations of code (2018, methodology): “The problem of predicting program properties by learning from big code has seen tremendous interest and progress in recent years [Allamanis et al. 2014; Allamanis and Sutton 2013; Bielik et al. 2016; Hindle et al. 2012; Raychev et al. 2016].”
- DOBF: A Deobfuscation Pre-Training Objective for Programming Languages (2021, positive): “It motivated other works studying deobfuscation of identifier names and identifier name proposal using n-grams (Allamanis et al., 2014; 2015), probabilistic models (Raychev et al., 2015; Bichsel et al., 2016; Vasilescu et al., 2017; Alon et al., 2018), and recurrent neural networks (Bavishi et al.,…”
- DeepBugs: a learning approach to name-based bug detection (2018, methodology): “The Naturalize tool suggests more natural identifiers based on an n-gram model [Allamanis et al. 2014].”
- Big Code != Big Vocabulary: Open-Vocabulary Models for Source Code (2020, methodology): “Another application are recommendation systems for variable, method, and class names [2, 3, 5] that employ relevant code tokens as the LM context.”
- Will They Like This? Evaluating Code Contributions with Language Models (2015, methodology): “which found that low-entropy refactorings likely constitute acceptable contributions to OSS projects [1].”
- Products, developers, and milestones: how should I build my N-Gram language model (2015, methodology): “However, Allamanis at al. have shown that language models can be used to detecting and enforcing team coding conventions [3] as well as suggesting accurate names of program entities such as variables, methods, and classes [5].”
- Synthesizing benchmarks for predictive modeling (2017, methodology): “Naturalize employs techniques developed in the natural language processing domain to model coding conventions [45].”
- Recovering clear, natural identifiers from obfuscated JS names (2017, background): “There have been substantial further applications of statistical models for code, in areas such as coding standards mining and checking [1], code summarization [17], idiom mining [3, 37], and bug localization [41].”
- Statistical Deobfuscation of Android Applications (2016, methodology): “The works of Allamanis et al.[8, 9] suggest names for Java program elements using n-gram language models and neural networks.”
- SmartPaste: Learning to Adapt Source Code (2017, unknown): “However, all variable usages are deterministically known beforehand (as the code is complete and remains unmodified), as in Allamanis et al. [1, 2].”
- Learning to Fuzz: Application-Independent Fuzz Testing with Probabilistic, Generative Models of Input Data (2016, methodology): “, based on n-grams [7, 9, 38], graphs [37, 42] and recurrent neural networks [43].”
- Modeling Vocabulary for Big Code Machine Learning (2019, background): “Some applications (e.g., pretty-printers [2]) may care about the layout of source code.”
- End-to-End Deep Learning of Optimization Heuristics (2017, background): “These include mining coding conventions [15] and idioms [14], API example code [53] and pseudo-code generation [54], and benchmark generation [8].”
- Deep Code Comment Generation (2018, methodology): “[1] develop a framework to learn the code conventions of a codebase and the framework exploits N-gram model to name Java identifiers.”