DEV Community

Sergiu Mureşan
Sergiu Mureşan

Posted on

Tips on how to comment your code

What are your thoughts on this?

I am constantly improving the series with whatever information I can get my hands on, therefore, please, do leave a comment, however positive/negative it is.

Thank you!

Top comments (6)

 
codevault profile image
Sergiu Mureşan

I fully agree

The problem is that there are times we don't create good code, we create bad code in a hurry and comment it (instead of refactoring it) due to time constraints. Couple that with working in a team of developers and comments become the norm. Unfortunately, we can't base our assumptions that the whole team will make good code and not create ambiguity with their naming.

If you don't work in a team, then by all means, don't use comments, that's what I usually do 99% of the time in my personal side projects.

Believe me, I wish we could simply get away from comments altogether since they:

  • Aren't linked to what the code actually does (changing code doesn't change the comment and vice-versa)
  • Are mostly boilerplate and sometimes add tons of unnecessary lines in our code.
Collapse
 
codevault profile image
Sergiu Mureşan • Edited

I agree, but it depends on the language. In a strongly typed language that is usually the case but when you don't even know what is the type of data that the function returns then you might need some comments.

Collapse
 
aruydv profile image
kuldeepydv

Are you using split screen windows 10 due to lack of time and workload is more.

Some comments may only be visible to logged-in visitors. Sign in to view all comments.