What are your “hard rules” about commenting your code?

前端 未结 21 1835
野性不改
野性不改 2020-12-31 16:09

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

21条回答
  •  时光说笑
    2020-12-31 16:13

    1. I comment public or protected functions with meta-comments, and usually hit the private functions if I remember.
    2. I comment why any sufficiently complex code block exists (judgment call). The why is the important part.
    3. I comment if I write code that I think is not optimal but I leave it in because I cannot figure out a smarter way or I know I will be refactoring later.
    4. I comment to remind myself or others of missing functionality or upcoming requirements code not present in the code (TODO, etc).
    5. I comment to explain complex business rules related to a class or chunk of code. I have been known to write several paragraphs to make sure the next guy/gal knows why I wrote a hundred line class.

提交回复
热议问题