• @Vigge93@lemmy.world
    link
    fedilink
    29
    edit-2
    5 months ago

    Comment should describe “why?”, not “how?”, or “what?”, and only when the “why?” is not intuitive.

    The problem with comments arise when you update the code but not the comments. This leads to incorrect comments, which might do more harm than no comments at all.

    E.g. Good comment: “This workaround is due to a bug in xyz”

    Bad comment: “Set variable x to value y”

    Note: this only concerns code comments, docstrings are still a good idea, as long as they are maintained

    • @balp@lemmy.world
      link
      fedilink
      25 months ago

      Docstring are user documentation, not comments. User documentation, with examples (tests), is always useful.