6.2. Misleading comments

Though commented-out code tends to be useless and confusing at best, even actual comments—the ones intended to communicate code’s purpose—can smell bad. One particularly nasty smell is a misleading comment.

Misleading comments are arbitrary in that they may suggest something that’s not necessarily true.[3] Sometimes they’re misleading and the poor programmer reading the comment and relying on that misinformation goes astray.

3 All comments are like that; they’re not executed with the code they’re commenting on so they can easily go stale.

Let’s look at a test where such misleading comments play their tricks on the unsuspecting programmer.

6.2.1. Example

The example in the next listing comes from a debt collection agency’s ...

Get Effective Unit Testing now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.