Popular

What are two reasons to write comments in your code?

What are two reasons to write comments in your code?

Commenting involves placing Human Readable Descriptions inside of computer programs detailing what the Code is doing. Proper use of commenting can make code maintenance much easier, as well as helping make finding bugs faster. Further, commenting is very important when writing functions that other people will use.

When should you comment on a code?

A handy rule of thumb is: a comment should only be added to answer a question that the code can’t. If you aren’t confused by what a piece of code is doing, but rather why it’s doing it at that moment, then a comment should be added.

Is it bad to comment code?

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.

READ ALSO:   Why would a shift be used defensively in baseball?

How much should I comment my code?

You should comment wherever you can – put comments that explain what you’re doing, and if you’re doing something tricky or unique be sure to explain that, as well. A good goal is to have 1 comment for every 1-4 lines of code.

Is it bad to write code without comments?

Writing code without comments is not friendly for the next person that comes along and is not sure what is going on. This article is only relevant with short pointless comments. However comments should be used more and certainly not less. I have been a programmer for over 25 years and can assure you that comments are good and not bad.

Do you need to add a comment to your code?

If the code is already simple and obvious, there’s no need to add a comment. Like, don’t do this nonsense: Still, there are times when no matter what you do to the code itself, a clarification comment is still warranted.

READ ALSO:   Is there a French manga?

Do developers do too much code commenting?

Peter Vogel responds to the furor about his contention that developers do too much code commenting. He says that documenting code, while it may be necessary, isn’t valuable. A few weeks back, my column on the value of comments in code caught a lot of comments itself.

Should you clutter your code with comments?

Bring up the topic and invariably (and soon) someone will tell you why you shouldn’t clutter your code with comments. One of the primary complaints about comments is that they add noise to the code’s signal. “Good code is self-documenting,” the saying goes, and adding comments can sometimes serve to mask bad code, and not for the better.