DEV Community

Discussion on: What little things make you happy while coding?

Collapse
 
gonzalezanguita profile image
Jose Tomas Gonzalez

I was taught that you should not use comments. To avoid comments your code should be written in a way that can be read like a comment.

I wrote a little article showing the difference of code that needs comments and other that it doesn't.

Collapse
 
ethan profile image
Ethan Stewart

A lot of truth to this, but an exception can and should be made when something merits an explanation of why it is the way it is. Comments should be few and far between in well-written code, but still used when there's an actual need. For me that's usually just when I had to dig to find a way to make something work when a more intuitive solution wouldn't work in that specific case.

Thread Thread
 
gonzalezanguita profile image
Jose Tomas Gonzalez

Indeed, some business concerns are just impossible to explain by code itself and as you've said, logic that by some black magic doesn't work.
The key is to know if comments are up-to-date with the code as refactors come and go and not everyone updates the comments.

Thread Thread
 
ethan profile image
Ethan Stewart

With this I fully agree, that's something I've been trying to improve on myself.

Collapse
 
6temes profile image
Daniel • Edited

There are comments and comments. The comments explaining what the code does are usually a symptom that the code is convoluted and difficult to understand even for the person who is writing it.

On the other hand, there are comments like:

# This solves a bug in the library Fubar that prevented the Baz 
# from being executed. See: https://github.com/fu_bar/baz/issues/454

Or:

# Temporalirly removed as per request in Issue #1243

Those make perfect sense to me.

Thread Thread
 
slavius profile image
Slavius • Edited

Works very well in commit messages when you have Bitbucket integrated with Jira. Hell of a difference!

Collapse
 
moopet profile image
Ben Sinclair

While I agree with not using comments where the code can demonstrate its own purpose and mechanism, I don't like absolutes like "don't use comments". An RFC number or something can be very helpful, or a link to where you found the code you just copy-pasted.