DEV Community

Discussion on: "Do not comment on your code, it should be self-documented". Well... I don't agree.

Collapse
 
rodelta profile image
Ro De la Rivera • Edited

After thinking and experimenting with this a lot, I'm convinced the rules are simple.

  • Inline comments only answer "why". What, where, who and how should be represented in the code by correct encapsulation and naming.

  • Comment external interfaces so they show in the editor. For example, a function should have the parameters commented, a class needs the constructor commented. This comment should never contain the name of the variable/parameter.

  • Comment after a bug fix, to avoid falling in the same error again.

That's it. Excessive commenting is lies waiting to happen.