3 ms·
Most commonly, the comments end up lying about the "what". Because so much of the "what" comments are boilerplate code that we unconsciously tune out, it's the
by kstenerud 4y ago
Most commonly, the comments end up lying about the "what". Because so much of the "what" comments are boilerplate code that we unconsciously tune out, it's the first to go stale and out of date since we also don't remember to change them when the "what" changes (and also it's a two-place change, which always falls out of sync).
Next up is the "how", although it's not as likely as the "what" since it's not as common (as it should be - you don't need to write a "how" about every list iteration).
The least likely to be a lie is the "why", since the circumstances leading to a "why" rarely change, and when they do, you usually end up replacing the whole section.
And so, your "what" should be almost entirely in self-documenting code, your "how" should be used judiciously, and your "why" probably won't be a problem.
The more unnecessary comments you write, the greater the risk of them going stale due to maintainers glossing over them. When they're a rarity, you take more notice.