liveBook · Manning

Comment

As explained in Simple Object-Oriented Design: Create clean, maintainable applications

A code comment is explanatory natural-language text embedded in source code to convey rationale, behavior, caveats, or other information not expressed by the code itself.

Code comments are natural-language notes placed beside code to preserve information the implementation cannot express well. Their main job is to explain why a decision exists: a business reason, a constraint, or the choice of one approach over another. Readable names, small units, and refactoring should explain implementation logic first; comments supplement them when that is not enough. section 2.2.3 section 2.5

Comments are especially useful around complex decision points. An involved conditional can be clarified with explanatory variables, smaller steps, or a concise explanation of the decision. Making that reasoning visible helps later maintenance and debugging. section 2.2.2

Comment the boundary, not the obvious

Prefer a comment that introduces the purpose of a difficult block—such as why a particular business rule is applied—over one that merely repeats what a clear statement already does. When extracting code into a helper would require an awkward signature or obscure variables shared across nearby lines, a block-level comment can retain the local flow while marking the next responsibility. section 2.2.3 section 2.5

Use comments deliberately to control future reading cost:

  • Explain decisions, motivations, and tradeoffs that clean implementation code cannot reveal. section 2.2.3
  • Separate substantial code blocks so readers can locate or skip a responsibility quickly. section 2.2.3
  • Refactor for legibility before commenting, but do not force a refactoring that makes surrounding code harder to follow. section 2.2.3
  • Review whether existing comments remain useful; both good and bad comments are worth discussing as part of documentation practice. section 2.4
Figure 2.2 Comments separating code blocks

A visual separation of code blocks illustrates how comments can provide navigational landmarks without splitting tightly connected code into artificial methods. section 2.2.3

Comments are not a replacement for understandable code. They can become stale or pointless, and some information may also belong in an internal wiki. A nearby comment, optionally linked to longer documentation, keeps important context close to the developer working in the IDE. section 2.2.3

How Simple Object-Oriented Design: Create clean, maintainable applications covers it

How deep it goes
Explains comment purposes and refactoring tradeoffs but does not prescribe a formal comment syntax or style standard.
Examples
Uses complex conditional decisions and comment-separated code blocks, plus prompts to compare good and bad comments.
What you can do after
Evaluate/understand when a comment should preserve rationale or structure that refactoring and naming do not communicate.
How it connects
Connects comments with refactoring, explanatory variables, method names, code legibility, maintenance, and debugging.

Also explained in

Compare how 10 books explain comment →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Simple Object-Oriented Design: Create clean, maintainable applications. The section links point to the parts of the book it draws on.