DEV Community

Cover image for Comment or No Comment's in Code
Adegoke Temitope
Adegoke Temitope

Posted on

Comment or No Comment's in Code

Comment or No Comment in Code

It's a general convention "Always comment your code".
Comments in code usually serve different purposes/intents:

  • Removing a block of code without deleting it
  • Extra information about a block of code, method, class, or its usage
  • Change annotations (use git please) and why the change
  • "In-solution documentation"

“Any fool can write code that a computer can understand. Good programmers write code that humans can understand.”

Matin Flower said the above (not me please), it's pointing out that developers should write code that humans can read, in my view, a self-documenting code.

I put comments in my code, especially if it is JavaScript because I can have a similar experience to typescript by using comments to explain method return types, parameter types, etc. but I also strongly hold the opinion that sometimes comments can be redundant and can be a source of noise to the code. For example, a user service that checks if a user session is still active named "checkUserSessionIsActive" is descriptive enough within its namespace and wouldn't need extra comments around it to explain what it does.

Also, I have seen developers use comments to apologize because they choose not to refactor, well that's bad, please don't use comments to apologize.

What is your take on this as a CTO, Developer Experience Engineer, etc do you comment on your code and why?

Top comments (0)