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

前端 未结 21 2025
野性不改
野性不改 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:37

    There are no hard rules - hard rules lead to dogma and people generally follow dogma when they're not smart enough to think for themselves.

    The guidelines I follow:

    1/ Comments tell what is being done, code tells how it's being done - don't duplicate your effort.

    2/ Comments should refer to blocks of code, not each line. That includes comments that explain whole files, whole functions or just a complicated snippet of code.

    3/ If I think I'd come back in a year and not understand the code/comment combination then my comments aren't good enough yet.

提交回复
热议问题