• Martin@feddit.nu
        link
        fedilink
        arrow-up
        0
        ·
        2 years ago

        Absolutely, although I see that as part of why

        Why is there a horrible hack here? Because stupid reason…

      • lad@programming.dev
        link
        fedilink
        English
        arrow-up
        0
        ·
        2 years ago

        Or if the what is so cryptic and esoteric that it would require the reader a couple hours of research to understand it.

        Also, I find it useful to summarise the what before code blocks if that can’t be summarised in a function name

  • SlopppyEngineer@lemmy.world
    link
    fedilink
    arrow-up
    0
    ·
    2 years ago

    Best comment ever was “It used to work like this but person at client demanded it work like that on this date” when the client complained it shouldn’t work like that.

    • conciselyverbose@sh.itjust.works
      link
      fedilink
      arrow-up
      1
      ·
      2 years ago

      That’s basically what comments are most useful for. When you’re doing something that’s not obvious, and want to make sure the “why” doesn’t get lost to time.

    • T. Hex@lemmy.dbzer0.com
      link
      fedilink
      arrow-up
      1
      ·
      2 years ago

      The best comments are “why” comments, the runner up is “how” comments if high-level enough, and maybe just don’t write “what” comments at all because everyone reading your code knows how to read code.

  • ImpulseDrive42@lemmy.world
    link
    fedilink
    arrow-up
    0
    ·
    2 years ago

    I had a old job that told me that code is “self documenting” if you write it “good enough”. And that comments were unnecessary.

    It always annoyed the heck out of me. Comments are imo more helpful than hurtful typically.

    Is it just me? Or am I weird? Lol.

    • Vigge93@lemmy.world
      link
      fedilink
      arrow-up
      0
      ·
      2 years 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