Skip to content
DevMeme
531 of 7590
CodeQuality Post #611 · source on Telegram

The Art of the Redundant Comment

Description

A screenshot of a tweet from user 'An @AnTheMaker' who writes, 'just found this in one of my old projects'. Below the text is an embedded image of a code snippet from a text editor. The snippet displays line number 52, which contains a line of PHP code: '$array = array(); // array'. The code itself is syntax-highlighted, with the variable in red, the function in purple, and the comment in grey. The humor stems from the utter redundancy of the comment. The code '$array = array();' is self-explanatory to anyone familiar with PHP, as it clearly initializes an empty array. The trailing comment '// array' adds no new information, perfectly illustrating a common anti-pattern where developers, especially early in their careers, write comments that merely state what the code already says, rather than explaining the 'why'

Comments

7
Anonymous ★ Top Pick The best comments explain why the code is doing something clever or weird. This comment explains that water is wet
  1. Anonymous ★ Top Pick

    The best comments explain why the code is doing something clever or weird. This comment explains that water is wet

  2. Anonymous

    Past-me achieved 100 % documentation coverage by naming the variable ‘array’ and commenting ‘// array’; future-me filed it under “why we can’t have nice things.”

  3. Anonymous

    This is the same code that passed three code reviews, got deployed to production, and somehow became a critical dependency that nobody wants to touch because "it's working fine in prod."

  4. Anonymous

    Ah yes, the holy trinity of redundancy: when your variable name, initialization function, and comment form a perfect tautology. This is what happens when you follow 'document everything' advice a bit too literally - it's like writing a function called `addNumbers()` that adds numbers and commenting it with `// adds numbers`. At least future archaeologists examining this codebase will have absolutely zero ambiguity about what `$array` contains... assuming they can stop laughing long enough to read the next line

  5. Anonymous

    Proof that metrics lie: $array = array(); // array - 100% comment coverage with negative information value, and a reminder this predates PHP 5.4

  6. Anonymous

    Declaring an empty array twice in PHP: because one idempotent init might not survive the next junior refactor

  7. Anonymous

    Peak legacy PHP: $array = array(); // array - the trifecta of pointless naming, self-evident comments, and pre-5.4 syntax; refactor to [], name it users_by_id, and watch your linter’s existential dread subside

Use J and K for navigation