Abstract
Human language is ambiguous, with intended meanings recovered via pragmatic reasoning in context. Such reliance on context is essential for the efficiency of human communication. Programming languages, in stark contrast, are defined by unambiguous grammars. In this work, we aim to make programming languages more concise by allowing programmers to utilize a controlled level of ambiguity. Specifically, we allow single-character abbreviations for common keywords and identifiers. Our system first proposes a set of strings that can be abbreviated by the user. Using only 100 abbreviations, we observe that a large dataset of Python code can be compressed by 15%, a number that can be improved even further by specializing the abbreviations to a particular code base. We then use a contextualized sequence-to-sequence model to rank potential expansions of inputs that include abbreviations. In an offline reconstruction task our model achieves accuracies ranging from 93% to 99%, depending on the programming language and user settings. The model is small enough to run on a commodity CPU in real-time. We evaluate the usability of our system in a user study, integrating it in Microsoft VSCode, a popular code text editor. We observe that our system performs well and is complementary to traditional autocomplete features.
Introduction
Programming languages are traditionally designed to be unambiguous so that compilers can parse them without error. However, this lack of ambiguity comes at a significant cost: verbosity. While natural languages (like English) are rife with ambiguity, humans use "pragmatic reasoning"—relying on context—to understand intended meanings efficiently.
Traditional autocomplete tools attempt to bridge this gap by predicting the next token, but they often present a list of suggestions that impose a "selection tax." Human-Computer Interaction (HCI) research suggests that the cognitive load of stopping to evaluate and select from a list can actually impede a programmer's flow. This paper explores whether we can intentionally introduce ambiguity into code entry via abbreviations and let a model resolve it using context, thereby reducing typing effort without increasing cognitive load.
System Architecture and Methodology
The authors propose a system called Pragmatic Code Autocomplete, which operates in three main stages: abbreviation selection, expansion modeling, and personalization.
Initially, the system identifies the top 100 tokens (keywords or common identifiers) that yield the highest compression if reduced to their first character. A specialized algorithm, CapCollisions, ensures that no single character maps to an unmanageable number of possible expansions, maintaining high potential accuracy.
The core of the system is a contextualized sequence-to-sequence (seq2seq) model. When a user types a line of shorthand (e.g., r s.r.size() instead of return self.request.size()), the model analyzes the abbreviated line alongside the previous 10 lines of code as context. It utilizes an LSTM-based encoder-decoder architecture with attention to rank the most likely full-line expansions. Furthermore, the system can be fine-tuned on a specific codebase to learn project-specific abbreviations for local variables.
Experimental Evaluation
The researchers evaluated the system using a massive corpus of open-source code from GitHub, sampling 100,000 files each for Python, Java, and JavaScript. This resulted in roughly 1.3 million lines of code paired with their preceding context for training and evaluation.
Offline Performance
In offline tests, the model proved that local context is almost always sufficient to resolve abbreviation collisions. For example, the abbreviation r might mean return in one block and range in another; the model resolves this with high precision.
As shown in the performance metrics, the system achieves 93% to 99% top-1 accuracy in reconstructing original code. Using just 100 abbreviations, the system can compress Python codebases by 15% and Java codebases by over 20%.
User Study and Integration
A study with 10 participants using a VS Code integration demonstrated that the system is highly complementary to traditional autocomplete. While users initially faced a learning curve, their speed increased significantly over time. The combination of "VS Code Default + Pragmatic Autocomplete" resulted in the lowest number of keystrokes, saving approximately 16% of total keystrokes compared to unassisted typing.
Discussion and Conclusion
Pragmatic Code Autocomplete demonstrates that intentional ambiguity, when paired with contextual modeling, can significantly improve the efficiency of code entry. By aiming for near-perfect accuracy, the system allows users to bypass the traditional selection menu, expanding whole lines instantly. Future work will focus on more intuitive discovery mechanisms for abbreviations and better handling of one-off local identifiers.
Summary updated