"Understand how to write meaningful and helpful comments that improve code readability and maintainability."
Abhishek Kumar
Writing comments in code is a fundamental yet often overlooked aspect of good software development. While code should be self-explanatory, well-placed comments can drastically improve clarity and make future maintenance easier.
Bad:
i++; // increment i
Good:
i++; // Move to the next item in the array
Outdated comments are worse than no comments. If the code changes, so should the comment.
Don't repeat what the code already tells.
Bad:
# Add a and b
result = a + b
Good:
# Combine user's previous and current scores
result = previous_score + new_score
// TODO: Refactor this to a reusable hook
// FIXME: Handle API error correctly
Use them consistently so others (and your tools) can track unfinished tasks.
Example in Python:
def add(a, b):
"""Return the sum of a and b."""
return a + b
Good comments make good code great. They're not just for others—they’re for you six months later, wondering what you were thinking.
Write less, but write clearly. Comment with purpose.