The article discusses the importance of effective code comments in Python, suggesting that improving code structure and naming can often replace the need for comments. It presents alternatives such as adding documentation strings, using descriptive names for functions and variables, and implementing tuple unpacking. The author highlights instances where comments can be helpful, but ultimately advocates for prioritizing clear code over commentary. By refactoring code for clarity, developers can often eliminate the need for comments, making the code self-explanatory.
Instead of a comment, consider whether you could add documentation for your function or improve the documentation, find a more descriptive name for a function or a variable.
Documentation strings are for conveying the purpose of function, class, or module, typically at a high level. Unlike comments, they can be read by Python's built-in help function.
Sometimes a non-obvious value may benefit from its own variable, but occasionally a comment is good enough.
When I find myself tempted to use comments excessively, I reconsider how I might refactor the code instead.
Collection
[
|
...
]