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

  • Authors:
  • Hongyu Zhang

  • Affiliations:
  • -

  • Venue:
  • WCRE '08 Proceedings of the 2008 15th Working Conference on Reverse Engineering
  • Year:
  • 2008

Quantified Score

Hi-index 0.00

Visualization

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.