Comment

Domain: Software Engineering

🎯 Motivation

Notes in code for humans. Explain why something is done, not what (the code shows what).

πŸ“‹ Concrete Example

Good comment: ’# Use binary search because the list is sorted - O(log n) instead of O(n).’ Bad comment: ’# increment i by 1.’ The first explains why; the second is obvious from the code.

πŸ”— Analogy

A comment is like a margin note in a textbook - β€˜This formula is used in physics.’ The note explains why, not what. The textbook (code) already shows what. Comments explain the reasoning behind the code.