Exploring Regularity in Source Code: Software Science and Zipf's Law

Hongyu Zhang
DOI: https://doi.org/10.1109/wcre.2008.37
2008-01-01
Abstract:Are there statistical regularities behind computer programming? In 1970s, Halstead proposed the software science theory which attempted to describe some of the regularities based on the direct measurement of lexical tokens in programs. The famous software science length equation models the relationship between program length and vocabulary. By analyzing the source code of twelve Java software systems collected from public software repositories, we find that Halstead's length equation does not hold for large-scale modern software systems. We discover that the distribution of lexical tokens in studied systems follows the Zipf's law (or more generally, Zipf-Mandelbrot law), which is an empirical law in statistical natural language processing. Based on the discovery of Zipf's law, we propose a revised software science length equation for describing the vocabulary-length relationship. Our new equation fits the real data well and achieves better accuracy than the original equation. Our study reveals that we could discover statistical regularities behind computer programming by mining software repositories.
What problem does this paper attempt to address?