How often should I comment my code?

You should comment exactly as much as you love your work! If you love your code a lot; go ahead and write your heart out all over the code. If you do not love your code at all, please do not write any comments, no one needs any more from you!

Should you write comments in code?

Good comments compliment your code, while bad ones pull readers away from the main points. Before putting any comments, ask yourself whether it would serve any purposes rather than distract people from comprehending your program. Good codes have rhythm while mediocre codes have a lot of pauses.

Are code comments bad?

Commenting code is on the generally-recognized list of code smells. But unlike most of the others on the list, comments are not always bad. Generally speaking, you should strive to minimize comments and let the code speak for itself, but it is just as important to include comments when the code cannot.

Which is better too many comments or too few comments?

Too many comments may be bad, if the comments do not add information about how the code works. Extra comments do not hurt anything. But too few comments is much worse, because even the author of some code cannot really understand it completely after a few months.

What should I write in comment?

Top ten tips for writing a great comment

  1. Read the article.
  2. Respond to the article.
  3. Read the other comments.
  4. Make it clear who you’re replying to.
  5. Use the return key.
  6. Avoid sarcasm.
  7. Avoid unnecessary acronyms.
  8. Use facts.

How do you write comment code?

The basics tenets of commenting your code are simple:

  1. Make them brief.
  2. Keep them relevant.
  3. Use them liberally, but not to excess.

Why inline comments are bad?

The more comments, the higher the maintenance cost. On top of this, if a comment were to get out of sync, it could confuse the reader which is also expensive in terms of time and the possible introduction of bugs. You can’t run comments, and a comment that lies is worse than no comment at all.

Why do people not comment code?

Two of the reasons have been given in the other answers: (1) the code and the comments often diverge because the compiler and unit tests enforce code updates but not comment updates, and (2) if the code can’t be understood on its own, there’s something wrong with it that should be fixed.

When is the best time to comment on a program?

Commenting is best done beforeactually writing the code for your program. Comments are specially marked lines of text in the program that are not evaluated. There are usually two syntactic ways to comment.

When do you not need to put a comment in code?

Most coders would chuckle and move on, ignoring the code smell. There are also times when you come across a comment that is redundant. If the code is already simple and obvious, there’s no need to add a comment. Like, don’t do this nonsense:

Why do you put clarification comments in your code?

Clarification comments are intended for anyone (including your future self) who may need to maintain, refactor, or extend your code. Often, a clarification comment is a code smell. It tells you that your code is too complex. You should strive to remove clarification comments and simplify the code instead because, “good code is self-documenting.”.

What do you use to indicate the end of a comment?

Line comments generally use an arbitrary delimiter or sequence of tokens to indicate the beginning of a comment, and a newline character to indicate the end of a comment. In this example, all the text from the ASCII characters // to the end of the line is ignored.

You Might Also Like