A theory of aspects as latent topics

Pierre Baldi, Cristina Videira Lopes, Erik Linstead, Sushil Krishna Bajracharya

TL;DR

This paper proposes a novel theory of aspects in software engineering, viewing them as "latent topics" that can be automatically discovered using statistical topic modeling. This approach allows for precise, information-theoretic measurement of "scattering" and "tangling" of concerns, providing a more robust and scalable way to understand and manage crosscutting concerns in software.

What Problem Does This Paper Address?

Aspect-Oriented Programming (AOP) has been around for over a decade, yet its practical value and theoretical underpinnings remain debated. While the concept of aspects (crosscutting concerns) is intuitive, concrete AOP solutions often fall short, leading to a disconnect between the promise and the reality. This discrepancy stems from a lack of a solid, empirically validated theory of aspects. Existing methods for identifying aspects are often manual, small-scale, or rely on assumptions about code structure that might not generalize. The authors aim to bridge this gap by providing a statistically grounded, unsupervised method for identifying and quantifying aspects at scale.

Methods

The core of this paper is the application of Latent Dirichlet Allocation (LDA), a statistical topic modeling technique, to software code. LDA models documents (in this case, source files) as mixtures of latent topics, and topics as mixtures of words. The authors adapt LDA to software by treating source files as documents and carefully selecting tokens (class names, method names, field signatures, etc.) to form the vocabulary.

Crucially, they leverage information theory to quantify "scattering" and "tangling." * Scattering of a concern (topic) is measured by the entropy of its distribution across files. High entropy means the concern is spread widely. * Tangling within a file is measured by the entropy of the file's distribution across topics. High entropy means the file deals with many different concerns.

This approach is "unsupervised," meaning it doesn't require pre-annotated data or specific assumptions about what aspects look like.

Datasets

The primary dataset is a large collection of 4,632 Java projects downloaded from Sourceforge, Tigris, and Apache, comprising approximately 38.7 million lines of code. This dataset was processed and stored in the Sourcerer infrastructure, a system developed by the authors for collecting, parsing, and analyzing software projects.

For smaller-scale validation, the authors also analyzed 5 individual open-source projects: JHotDraw, Jikes, PDFBox, JNode, and CoffeeMud.

Key Insights and Ideas

  • Concerns are Latent Topics: The most fundamental idea is that software concerns are not explicitly defined but are "latent topics" that can be discovered through statistical analysis of code.
  • Scattering and Tangling as Entropy: Using information theory (entropy) provides a precise, quantitative way to measure how spread out (scattered) a concern is across a codebase and how mixed up (tangled) different concerns are within a single file.
  • Unsupervised Discovery: The LDA approach allows for the discovery of aspects without prior knowledge or manual annotation, making it scalable and less prone to human bias.
  • General vs. Project-Specific Concerns: The analysis revealed a set of "general-purpose" concerns (like exception handling, logging, concurrency) that appear across many projects, alongside "project-specific" concerns.
  • Sigmoidal Tangling Curves: Tangling behavior across projects consistently follows an inverted "S" shape, suggesting a parameterized model for tangling can be developed.

Key Results

  • Validation of AOP Hypotheses: The large-scale experiments provided strong evidence that crosscutting concerns, characterized by scattering and tangling, exist to a substantial degree in software projects, validating the first AOP hypothesis.
  • Identification of General Concerns: The analysis identified about two dozen high-level, crosscutting concerns that are likely to affect most new Java projects.
  • Empirical Measurement: The method successfully identified and quantified scattering and tangling for both the entire repository and individual projects. For instance, in JHotDraw, concerns like "Persistence" and "Undo" showed high scattering entropy, aligning with prior research.
  • Parameterized Tangling Model: A simple two-parameter model based on the sigmoid function accurately captured the tangling behavior of software, explaining on average 94.7% of the variation in tangling.
  • Comparison with Prior Work: The identified concerns and their scattering/tangling levels showed significant agreement with aspects previously identified through manual analysis, identifier analysis, and other aspect mining techniques, suggesting the LDA approach is both valid and extends previous methods.

Limitations and Future Work

  • Vocabulary Selection: While the authors explored various vocabulary selection strategies, the choice of tokens significantly impacts the quality and interpretability of the discovered topics. The optimal strategy might be domain-specific.
  • Interpretation of Topics: While LDA is unsupervised, human judgment is still needed to interpret the meaning of the discovered topics and assign meaningful concern names.
  • Language Specificity: The current study is focused on Java. While the theory is expected to generalize, further empirical validation on other programming languages and representations (like UML) is needed.
  • "Badness" of Scattering/Tangling: The paper acknowledges that the hypothesis that excessive scattering and tangling are "bad" is still an open question, though some evidence suggests this is the case.
  • Future Work: The authors suggest integrating this approach into development tools (like IDEs) to track concerns and their scattering/tangling throughout the software development lifecycle. They also propose further research into how this understanding can inform better software design and refactoring.

Summary updated

Abstract

After more than 10 years, Aspect-Oriented Programming (AOP) is still a controversial idea. While the concept of aspects appeals to everyone's intuitions, concrete AOP solutions often fail to convince researchers and practitioners alike. This discrepancy results in part from a lack of an adequate theory of aspects, which in turn leads to the development of AOP solutions that are useful in limited situations. We propose a new theory of aspects that can be summarized as follows: concerns are latent topics that can be automatically extracted using statistical topic modeling techniques adapted to software. Software scattering and tangling can be measured precisely by the entropies of the underlying topic-over-files and files-over-topics distributions. Aspects are latent topics with high scattering entropy. The theory is validated empirically on both the large scale, with a study of 4,632 Java projects, and the small scale, with a study of 5 individual projects. From these analyses, we identify two dozen topics that emerge as general-purpose aspects across multiple projects, as well as project-specific topics/concerns. The approach is also shown to produce results that are compatible with previous methods for identifying aspects, and also extends them. Our work provides not only a concrete approach for identifying aspects at several scales in an unsupervised manner but, more importantly, a formulation of AOP grounded in information theory. The understanding of aspects under this new perspective makes additional progress toward the design of models and tools that facilitate software development.
BibTeX
@inproceedings{baldi2008theory,
  author = {Pierre Baldi and Cristina Videira Lopes and Erik Linstead and Sushil Krishna Bajracharya},
  title = {{A theory of aspects as latent topics}},
  booktitle = {OOPSLA},
  year = {2008},
  doi = {10.1145/1449764.1449807},
}
Figure