• magic_lobster_party
    link
    fedilink
    911 months ago

    Comments should only be used to describe stuff that’s otherwise difficult to convey with code.

    • @[email protected]
      link
      fedilink
      1811 months ago

      The best explanation I’ve ever heard is:

      Comments should state the ‘Why’ never the ‘What’.

      • @[email protected]
        link
        fedilink
        111 months ago

        There are some cases though where the code is just complicated for reasons outside of your control, in which case “what” comments are good - but they should never be taken at face value, but only used as a first step in understanding the code. There’s a significant risk of the code not actually doing what the comment says.

    • @dukk
      link
      311 months ago

      Yeah. Most of the time I use comments in my algorithms, as they often use some weird optimized black magic which are difficult to understand without comments.