Correct Code, Wrong Comments: Pointer Chasing in Zlib

Correct code but wrong comments in zlib reveals the engineering challenge of maintaining comments in sync with code.
The article uses a Hacker News discussion to focus on the mismatch between code and comments in the zlib compression library, calling it "pointer chasing"—where readers are forced to cross-reference outdated comments with actual code. It analyzes why comments become outdated: lack of automatic verification, decades of iteration, and early design origins. The article notes that pointer chasing also metaphorically describes the mental burden on readers, especially dangerous in low-level libraries. It offers three implications for developers: code is truth, comments need review, and static analysis tools help. Although community discussion is low, the topic has universal engineering significance. The conclusion emphasizes that wrong comments are more dangerous than no comments.
Introduction: When Comments Contradict Code
In software development, comments are supposed to be the manual for code, helping newcomers understand complex logic. But sometimes, comments become a source of misleading information. A discussion on Hacker News focused on zlib—a compression library relied upon by countless projects—where a piece of code does not match its comments. The author calls this phenomenon "Pointer Chase": readers, in order to understand the code, must follow clues in the comments to trace the true meaning of a pointer, only to discover that the comments are outdated or wrong. This paradox of "correct code, wrong comments" exposes a frequently overlooked corner of code maintenance.

The Trap of Comments: A Specific Case in Zlib
According to the discussion on Hacker News, a section of code in zlib involving pointer operations has comments that describe intentions that deviate from actual behavior. Although the original content does not provide specific code snippets, the core of the discussion is that comments may be based on earlier versions of logic and, as the code evolves, are not updated in sync, causing confusion for readers. The metaphor of pointer chasing vividly depicts the process of readers repeatedly cross-referencing code and comments—like chasing a moving target in a maze.
Why Comments Become Outdated
The separation of comments and code is a classic challenge in software engineering. Code is the sole truth executed by machines, while comments are manually maintained documentation lacking automatic verification mechanisms. When developers modify code, they often neglect to update comments, especially during emergency fixes or refactoring. As a long-standing C library, zlib has undergone decades of iteration, and some comments may originate from early designs and no longer fully match the current implementation.
C lacks the modularization and interface description mechanisms of modern languages; function comments often rely on manual maintenance by developers, and compilers do not verify consistency between comments and implementation. As a library written to the C89 standard, zlib's code style formed before the widespread adoption of documentation tools like Doxygen. Function header comments are mostly handwritten formats, not bound to the type system or test cases. In addition, zlib has long maintained ABI compatibility, and many internal functions are directly called by external projects. During refactoring, for compatibility reasons, often only the implementation is changed and not the comments, further exacerbating comment drift.
The Deeper Meaning of Pointer Chasing
"Pointer chasing" not only refers to pointer operations in code but also metaphorically describes the mental burden on readers when understanding code. When comments claim that a pointer points to a specific structure but the actual code uses it for another purpose, readers need extra reasoning to bridge the gap. This cognitive load is particularly dangerous in low-level libraries, as any misunderstanding can lead callers to misuse the API.
Implications for Developers
- Code is truth: When comments and code conflict, code behavior should prevail, and verification should be done through tests.
- Comments need maintenance: Incorporate comment updates into the code review process to prevent them from becoming historical relics.
- Tool assistance: Use static analysis tools to detect inconsistencies between comments and code, although such tools are still immature.
Inconsistency between code and comments is not always an error—sometimes comments describe the "contract" or historical intent of a function, while the code makes compromises for performance optimization or platform adaptation. When reading, developers should distinguish between "descriptive comments" (explaining current behavior) and "normative comments" (declaring interface contracts). If comments declare preconditions or ownership semantics that the code does not satisfy, it may be a potential defect rather than mere obsolescence. Therefore, when facing pointer chasing, a safer approach is to combine caller code and unit tests to determine the true semantics, rather than simply taking the code as the sole truth.
Community Reaction and Discussion Value
The post received 4 points and 2 comments on Hacker News. The discussion热度 is not high, but the topic itself is universal. Comments may involve a debate on the value of comments: one side believes comments should be minimized to let code self-explain; the other side believes key algorithms still need comments for assistance. This divergence reflects the diversity of engineering practices.
Lack of Multi-Source Perspectives
Since the original material comes only from a brief summary on Hacker News, lacking detailed technical analysis and in-depth community discussion, this article cannot present cross-validation from more independent sources. Readers who wish to learn more can consult the zlib source code or relevant code review records.
zlib uses the zlib License, allowing free use and modification, so it is embedded or linked by numerous projects such as the Linux kernel, Git, and the PNG specification. Many comments in its source code can be traced back to the original implementations by Jean-loup Gailly and Mark Adler in the 1990s. Subsequent maintainers, following the principle of minimal changes, prioritize ensuring the stability of the compressed data format. This engineering strategy of "freezing the core, modifying cautiously" makes zlib a typical sample for studying comment evolution in long-term maintained codebases.
Conclusion: The Paradox of Comments and Engineering Culture
The "pointer chasing" phenomenon in zlib reminds us that comments are not always better when there are more of them; they need to evolve in sync with code. While pursuing code quality, we should also pay attention to the accuracy of comments. After all, wrong comments are more dangerous than no comments—they may lead readers in the wrong direction.
One-line Summary
Correct code but wrong comments in zlib reveals the engineering challenge of maintaining comments in sync with code.
Paragraph Summary
The article uses a Hacker News discussion as a starting point to focus on the mismatch between code and comments in the zlib compression library, calling it "pointer chasing"—where readers are forced to repeatedly cross-reference outdated comments with actual code. The article analyzes why comments easily become outdated: comments lack automatic verification mechanisms, zlib has undergone decades of iteration, and some comments originate from early designs. The article points out that "pointer chasing" not only refers to pointer operations but also metaphorically describes the mental burden on readers when understanding code, which is particularly dangerous in low-level libraries. It offers three implications for developers: code is truth, comments need to be included in the review process, and static analysis tools should be used. Although community discussion is not intense, the topic has universal engineering significance. The conclusion emphasizes that wrong comments are more dangerous than no comments.
Related articles

The Bottleneck of AI Programming Isn't Generation: Why Software Factories Collapse
After AI coding tools went mainstream, PR review quality dropped and incidents rose. The speaker argues the bottleneck isn't code generation but models' inability to sustain maintainability.

Gemini 4 Neon Hands-On: 10 Hours to Achieve What Opus Couldn't in Days, 20x Faster Warm Start
Google's surprise Gemini 4 Neon release made critic Theo change his tune: 10 hours to finish what Astra couldn't in ten days, 20x faster warm start, coherence beating Opus.

Gemini 4 Neon Hands-On: Which $20 AI Subscription Should You Choose?
Bilibili creator tests Gemini 4 Neon: composite intelligence index 61, beating Claude Opus 5.5, with API 25% cheaper. With a $20 budget, how to choose between Google AI Pro, Claude Pro, and ChatGPT Plus? Includes three must-know pitfalls and recommendations by user type.