DEV Community

Discussion on: We Don't Need No Steenking Comments

Collapse
 
curtisfenner profile image
Curtis Fenner • Edited

Certain kinds of comments are very useful.

Many comments that get written range from useless to harmful (because they actually lie/mislead). However, I think there's many more comments that aren't written but should be.

The code says what the computer does. If you are a programmer, then you can read the code. Unless you're doing something absurdly tricky, you don't need comments to explain what the code is doing; if you feel like you need comments to explain the programming language, you are usually doing something wrong. This is the category of comments which are useless or harmful; there are often too many of these.

Code cannot speak for itself in why it is written one way.

Sometimes these are still technical details, like performance, allocation, and security; these are generally not encodable in the programming language itself. These aspects of the code deserve comments, since there are pertinent technical details that cannot be a part of the code itself.

There are also outside / product concerns which the code may execute but it's unclear what the actual requirement is (why does this job execute every Monday? Is there something special about Mondays, or does it just need to be done 'often enough'? How often is 'enough'?)

These are the comments that are very useful. I don't see enough of them.

Collapse
 
ferricoxide profile image
Thomas H Jones II

For me, it's usually a "breadcrumbs" exercise. I have to switch projects and languages with a non-trivial degree of frequency. If someone asks me to re-visit something, having the comments helps job my memory for why I did something a given way (especially if it's been many months and I've changed the way I tend to do a given thing).