Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are your "hard rules" about commenting your code?

I have seen the other questions but I am still not satisfied with the way this subject is covered.

I would like to extract a distiled list of things to check on comments at a code inspection.

I am sure people will say things that will just cancel each other. But hey, maybe we can build a list for each camp. For those who don't comment at all the list will just be very short :)

like image 778
alfinoba Avatar asked Sep 27 '08 02:09

alfinoba


People also ask

Why is it important to comment 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 not comment code?

Common reasons that people cite for not writing comments include: Good code should be self-documenting. If you can't understand the code from reading it, then the code's not good and should be rewritten.


2 Answers

Documentation is like sex; when it's good, it's very, very good, and when it's bad, it's better than nothing

like image 75
Pablo Fernandez Avatar answered Jan 03 '23 20:01

Pablo Fernandez


The only guaranteed place I leave comments: TODO sections. The best place to keep track of things that need reworking is right there in the code.

like image 20
Rich Avatar answered Jan 03 '23 20:01

Rich