arXiv(opens in a new tab)cs.SESep 2026Cited by 1 paper on PaperVantage

Manuscript Offprint

arXiv:2609.09242

Talking to Itself While Coding: What Makes Comments Help Code Generation?

Dangfeng Pan, Zhensu Sun, Cenyuan Zhang, David Lo, Xiaoning Du

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

Abstract

Large Language Models (LLMs) often generate natural-language comments while writing code, and these comments become part of the context used to generate the code that follows. However, it remains unclear which properties of comments affect code-generation performance. We study this question through observational analyses and controlled interventions. On LiveCodeBench, neither comment frequency nor broad comment intent reliably predicts pass@1. We then prefill weaker recipient models with comment blocks written by stronger source models, allowing us to separate comment surface form from the solution content they convey. Comments from source solutions that pass the tests raise recipient pass@1 by 17.2% on average. In contrast, comments describing failed solutions provide no reliable gain, while comments written for a different problem reduce pass@1 by 20.8%. Finally, across a wide range of models and prompt variants, most recipient models show no significant recovery of the external-comment gain, and the best case recovers only 24%. These results show that comments help code generation not merely because they are comments, but because they can provide correct solution content that prompting cannot reliably elicit.

1 Introduction

Code comments have long been studied as text for human readers. They explain rationale to future maintainers and share intent with collaborators. Empirical work has shown that informative comments measurably improve human program comprehension (Tenny, 1988). Subsequent taxonomies classify comments by intent and trace how each category supports a distinct maintenance activity (Storey, 2005; Pascarella and Bacchelli, 2017).

In LLM-based code generation, the reader changes from a human to the model itself. The comments and the code are emitted in the same forward pass by the same model. The model reads its own comments as context for the code that follows. We call these self-emitted comments, and their role in the model's own solution is not obvious. These comments are not free: they are billed as output tokens (Pan et al., 2025), and whether they can be safely suppressed depends on whether they causally help.

Do these comments causally affect the model’s own pass@1? Prior work has shown that natural-language preambles in code generation can help (Jiang et al., 2024; Chen et al., 2024; Shi et al., 2025; Di and Zhang, 2025; Jiang et al., 2026), but has not isolated which of their properties—surface form, line order, topic, intent, or the correctness of the solution they describe—is responsible. As a first observational check, we ask whether the most visible properties of natural comments provide a simple explanation for pass@1. We begin with comment volume and surface form. If these properties provided such an explanation, we would expect some consistent association between commenting behavior and performance. On LiveCodeBench (Jain et al., 2024), OpenReasoning-Nemotron-32B and Gemini-2.5-Pro-03-25 reach 81.0% and 81.5% pass@1 respectively, while self-emitted comments account for 0.1% of Nemotron’s output tokens and 71.4% of Gemini’s: a 700-fold gap that is invisible in pass@1. Among the 16 models scoring above 80.0% pass@1, commenting rates range from under 2.0% (4 models) to over 30.0% (5 models), showing no apparent link to pass@1.

In addition to the volume of comments, the intent of the comments also fails to track pass@1. Specifically, we label every comment across 13 models along the WHY/WHAT axis from comment taxonomies (Storey, 2005; Pascarella and Bacchelli, 2017)—whether it explains a choice or describes what the code does, and check whether models that

∗^{*}Corresponding author.

explain choices more often tend to score higher. We find that stronger models do explain choices a bit more often ( ρ=+0.61\rho = +0.61, raw p=0.027p = 0.027), but the trend does not survive Bonferroni correction. Therefore, from the natural distribution alone, neither comment volume/form nor coarse intent provides a reliable explanation for pass@1. This observational result cannot determine whether comments causally matter, so we turn to a controlled intervention (Section 4). We prefill a weaker recipient model's decoding context with a comment block from a stronger source model, and let the recipient continue from there, then vary only the comment's content while holding the recipient, prompt, and problem fixed. The source is chosen to be strong for a reason: its comments are correct when its own solution passes the tests and wrong when it fails, letting us control content correctness directly instead of merely measuring it. The external prefix is thus a measurement instrument rather than a model of natural self-commenting: it identifies what property a comment must have to help, and Section 4.2 then asks whether the model's own comments can supply that property.

The intervention separates which property of the comment moves pass@1. Correct comments raise the recipient’s pass@1 by 17.2% on average across the 12 (recipient, source) pairs. Same-form comments with wrong content leave pass@1 unchanged. Comment-shaped text on the wrong topic damages pass@1 by 20.8%, and length-matched random text damages it by 17.9%. Pass@1 changes with whether the comment describes a correct solution, not with what the comment looks like.

A natural follow-up question is whether the recipient can produce a comparable comment from its own prompt, without an external source. Across 14 models and 10 prompt variants (Section 4.2), the answer is largely no. Models follow what the prompt asks at the surface, such as producing more or fewer comments, or adopting different styles. However, the best prompt recovers at most about 24% of the external-comment lift, and the same instruction can move pass@1 in opposite directions on different recipients. Prompt engineering controls what the comments look like, but cannot reliably control whether their content describes a correct solution.

The overall structure of our study is depicted in Figure 1. In summary, the natural distribution of self-emitted comments does not track pass@1. Under controlled intervention, a correct comment from a stronger model lifts a weaker model's pass@1 while prompting the weaker model to write its own comments falls short. Talking to itself is not enough, and what matters is whether the talk carries correct solution content. To facilitate reproducibility, we release our code, generation outputs, per-problem pass/fail evaluations, and per-cell statistical summaries at https://github.com/pdfCN/What-Makes-Comments-Help-Code-Generation.

References (2)

  • high-level approach, key observations, edge cases, complexity
  • include_reasoning