Home Knowledge Base Comments as Deodorant

Comments as Deodorant is a code smell where developers use comments to explain, justify, or apologize for code that is complex, unclear, or poorly structured — applying documentation as a bandage over design problems instead of fixing the underlying issues, producing code where the comment reveals that the code itself needs refactoring, and perpetuating the misconception that a well-commented mess is equivalent to clean code.

What Is Comments as Deodorant?

The smell occurs when comments exist because the code cannot speak for itself:

Why Comments as Deodorant Matters

Good Comments vs. Bad Comments

Not all comments are deodorant. The distinction is what the comment adds:

Comment TypeExampleGood or Smell?
Why (intent)// Retry 3x to handle transient network failuresGood — explains reasoning
Warning// Thread-unsafe — must be called from synchronized blockGood — non-obvious constraint
Legal/Regulatory// Required by GDPR Article 17Good — external mandate
What (narration)// Loop through users and check their statusSmell — code should say this
Decoder// x is the user ID, y is the product IDSmell — use good variable names
Apology// I know this is complicated but...Smell — fix the complexity

Refactoring Approaches

Extract Method with Descriptive Name: Replace a commented block with a named method:

Rename Variables/Methods: Replace cryptic names with descriptive ones, eliminating the need for decoding comments.

Introduce Constants: Replace magic numbers with named constants, eliminating explanation comments.

Extract Variable: Introduce well-named intermediate variables that make complex boolean logic readable without comments.

Tools

Comments as Deodorant is apologetic coding — the practice of writing explanations for design failures instead of fixing the failures themselves, producing codebases that smell better on the surface while the underlying structural problems accumulate, leaving every future developer to read both the apology and the mess it was written to excuse.

comments as deodorantcode ai

Explore 500+ Semiconductor & AI Topics

From EUV lithography to CUDA optimization — search the full knowledge base or chat with our AI assistant.