# About GenAI writing code comments
> **In any case, never use AI to comment your code.**
In the age of ChatGPT and other AI tools that "help" generate code, we’ve started noticing a strange trend: comments in natural language that simply restate what the code already conveys.
This is, perhaps, one of the biggest issues with using [[GenAI - Generative Artificial Intelligence|Generative AI]] for code ; useless comments. Why? Because they create a false sense of clarity and confidence, giving the illusion that everything is well-explained when it’s not. Many people believe that code without comments is inherently bad. Nothing could be further from the truth.
Good code is code you can understand.
- If you can understand it without comments, it’s good code.
- If you can’t understand it without a comment, add a comment (if possible, try to change the code so that the comment is not required anymore).
- If you still can’t understand it with the comment, the code is still bad.
Now, consider this: more often than it should, comments are not updated when the code they describe changes. This makes code with comments on every line quickly become misleading.
My rule of thumb:
- If an AI can’t understand your line of code or [[function]], you need a comment that the AI cannot generate.
- If the AI can understand it, you don’t need a comment.
In any case, never rely on AI to comment your code.
```python
# Don't
def main(destination_path: pathlib.Path):
"""Generate a password file."""
# Download all the wordlists
word_lists = map(get_words, WORDS_URLS)
# Remove duplicates
unique_words = sorted(set(itertools.chain(*word_lists)))
# Sort by length
sorted_by_length = sorted(unique_words, key=len, reverse=True)
# Write
destination_path.write_text("\n".join(sorted_by_length))
print(f"Wrote the passwords file to {destination_path}")
# Do
def generate_password_file(destination_path: pathlib.Path) -> None:
word_lists = map(get_words, WORDS_URLS)
# Sort unique because of later sort by length.
# Timsort being stable, and set being unordered,
# this will keep the order of words equal in length over multiple runs.
unique_words = sorted(set(itertools.chain(*word_lists)))
sorted_by_length = sorted(unique_words, key=len, reverse=True)
destination_path.write_text("\n".join(sorted_by_length))
print(f"Wrote the passwords file to {destination_path}")
```