Over-commented code is often more difficult to understand than code without comments. Little notes back and forth from all the different maintainers of a project can often get cluttered. You spend more time reading the comments than you do the actual code.
Often cited as one of the most useful and least used programming conventions, a comment is a text note added to source code to provide explanatory information, usually about the function of the code. Comments are usually helpful to someone maintaining or enhancing your code when you are no longer around to answer ...
Periods are for the end of a sentence. Comments are not necessarily full sentences. Comments, in general, should be sentences.
What Are the Different Types of Comments in Python? There are three types of comments: single-line, multi-line, and docstring comments.
I'll just point you to Jeff Atwood's wonderful post on the subject, which hits the nail right on the head.
In all my career, I have never come across that wonderful beast "self-documenting code". Maybe I've just been unlucky, but I'm beginning to suspect it doesn't actually exist.
Every once in a while I run across code that is so elegantly partitioned, has such compellingly obvious method, field and variable names that everything I need to know is obvious from the code.
In the general case, only really great code gurus write such code. The rest of us cobble together something that works.
"One of the leads instructed his developers not to use comments as they are too "old fashioned", and a couple of other developers indicated that they never use comments because they feel all they do is clutter up the code."
If I ever heard a developer I was working with talk like this, I would correct them. If I didn't have the necessary rank to correct them, I would leave the job.
Very clearly written code, with good identifiers -- the stuff sometimes referred to as 'self-documenting' -- does a fine job of illustrating what the code is doing. That's fine as far as it goes. The job of the comments is to explain why.
This topic tends to be discussed a lot, but here are my US$0.02 on the subject:
The problem with comments is that they tend to stay long after the code that was commented has changed or even been deleted.
As a rule of thumb I'd only comment public API and difficult to understand algorithms.
Don't use comments to explain what you did - that's what the code is for, use comments to explain why you did it.
Diomidis Spinellis just wrote a nice column for IEEE column (quoted on his blog), outlining the problem, and a few solutions:
When commenting, we’re always a couple of keystrokes away from disaster: restating the code’s function in English. And that’s when problems start.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With