Overview
Comments differ from most other syntaxes available in programming languages; it is not executed. This might lead to situations where, after code rework, the comments around it were left intact and no longer true to what they described. First and foremost, this situation should not even happen, as good comments from the “Why” Comment family are not susceptible to this situation. If the comment explained “what” was happening, then it will be relevant as long as the code it explains is intact. Of course, “What” Comments are a Code Smell themselves, and so is Duplicated Code.
This might generally happen within docstrings in real-life scenarios, which developers usually find in methods exposed to other users.
Causation
The developer was in a hurry and did not double-check that everything was up-to-date after the changes. A passing unit test could also reaffirm him - there is no practical automated way to check for the correctness of comments/docstrings.
Problems
The developer does not know whether he should trust the method's signature or comment.
Example
1def rename_description(product, manufacturer):
2 """
3 Adds the manufacturer footer to the
4 products description.
5 """
6 ...Refactoring
- Remove Inconsistency
Sources
- ORIGIN
- PARENTAGELinguistic Antipatterns: What they are and how developers perceive them2015
- PARENTAGE1999 · ISBN 978-0201485677