Demystifying code snippets in code reviews: a study of the OpenStack and Qt communities and a practitioner survey

Beiqi Zhang, Liming Fu, Peng Liang, Jiaxin Yu, Chong Wang

TL;DR

While code snippets appear in fewer than 5% of code review comments, they are a high-impact communication tool with a 62% acceptance rate. This study reveals that developers overwhelmingly value snippets for their clarity and "copy-pasteability," primarily using them to suggest improvements in maintainability and coding style.

What Problem Does This Paper Address?

Modern Code Review (MCR) is a cornerstone of software quality, but it relies heavily on text-based communication which can be ambiguous or insufficient for complex logic. While we know developers use code snippets to bridge this gap, there has been little empirical data on how they are used, why they are provided, and whether they actually lead to better outcomes.

The authors set out to demystify the role of these snippets by investigating their frequency, the intent behind them, and the factors that lead a developer to either adopt or reject a reviewer's "code-based" suggestion.

Methods

The researchers employed a mixed-methods approach consisting of two distinct phases:

  1. Repository Mining & Manual Labeling: The team analyzed 127,182 review comments from the OpenStack and Qt communities. After filtering out bot-generated comments and irrelevant files, they manually labeled 69,604 comments. They identified 3,213 comments containing snippets and used Open Coding and Constant Comparison (techniques from Grounded Theory) to categorize the purposes and developer reactions.
  2. Practitioner Survey: To validate their findings and gain deeper "why" insights, they surveyed 63 industry practitioners (mostly with 5+ years of experience). This helped bridge the gap between what is visible in the data and what developers actually feel during the review process.

Datasets

The study utilized data from two massive, long-running open-source ecosystems that use the Gerrit review tool:

  • OpenStack: Specifically the Nova (cloud computing) and Neutron (networking) projects, primarily written in Python.
  • Qt: Specifically Qt Base and Qt Creator, primarily written in C++.
  • Survey Data: 63 valid responses from a mix of open-source contributors and developers at major tech firms like ByteDance, Alibaba, and Tencent.

Key Insights and Ideas

  • Reviewers are the Primary "Coders" in Comments: Over 86% of snippets are provided by reviewers rather than the original authors. This suggests snippets are a tool for instruction and critique rather than just a way for authors to explain their existing work.
  • Maintainability Over Bug-Fixing: The most common reason for providing a snippet isn't to fix a "bug" (Correcting Code), but to improve Maintainability (making code simpler or more readable). Developers are using snippets to teach "clean code" principles.
  • The "Copy-Paste" Expectation: A major "aha" moment from the survey is that developers don't just want a snippet to be correct; they want it to fit. If a snippet requires significant refactoring or re-indentation to integrate, its value drops significantly.
  • Snippets as Ambiguity Killers: 75% of survey respondents noted they provide snippets specifically when "code is more illustrative than words." It acts as a shortcut to bypass the limitations of natural language when describing complex logic or structural changes.

Key Results

  • Frequency: Snippets are rare, appearing in only 4.6% of review comments.
  • Acceptance: Developers accepted snippet-based suggestions 62.1% of the time.
  • Purpose: 83.9% of snippets are "Suggestions" (recommending changes), while the rest are "Citations" (referencing existing code for context).
  • Rejection Reasons: When suggestions were rejected, the top reasons were Difference in Opinion (31.1%) and the Reviewer’s Suggestion being Flawed (24.0%).
  • Sentiment: 73% of practitioners hold a positive attitude toward receiving snippets, viewing them as helpful and direct.

Limitations and Future Work

The authors acknowledge several constraints:

  • Language Bias: The data is limited to Python and C++ projects. Usage patterns might differ in languages with different verbosity or tooling (e.g., Java or Go).
  • Survey Size: While the 63 respondents were highly experienced, the sample size is relatively small compared to the global developer population.
  • Platform Specificity: The study focused on Gerrit. Review cultures on GitHub or GitLab, which have different UI treatments for "suggested changes," might yield different results.

Future Work: The team plans to expand the study to include GitHub pull request data, explore Java-based communities, and conduct deeper interviews to understand the specific "purposes" authors have when they do provide snippets.

Summary updated

BibTeX
@article{zhang2024demystifying,
  author = {Beiqi Zhang and Liming Fu and Peng Liang and Jiaxin Yu and Chong Wang},
  title = {{Demystifying code snippets in code reviews: a study of the OpenStack and Qt communities and a practitioner survey}},
  journal = {Empir. Softw. Eng.},
  year = {2024},
  doi = {10.1007/s10664-024-10484-2},
}
Figure