DEV Community

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

Collapse
 
lorenzotrojan1 profile image
Lorenzo Trojan • Edited

Too many comments are not just useless, they're detrimental to legibility, and are a typical feature of poorly designed code

As a rule of thumb:

  1. (90% of comments - docstring) Clarify function signatures, in particular types
  2. (9% of comments - docstring) Occasionally provide a code snippet on how to use the function
  3. (0.9% of comments - docstring) Occasionally refer to one or two other related functions, especially when the other functions are not totally independent (for example when function calls should follow a given sequence)
  4. (0.1% left everywhere) these comments are used to explain complex lines of code and may consists of references to whitepapers and documentation elsewhere and should be used primarily in functions implementing a complex/new algorithm

Feeling completely lost in someone else's code is not at all correlated with amount of comments, it's associated with poorly designed code