• Bappity
    link
    fedilink
    English
    54
    edit-2
    11 months ago

    me when first starting out at a job commenting everything I can
    VS
    me a couple years in completely lost because I never updated the comments and now none of them make any sense whatsoever

    • @[email protected]
      link
      fedilink
      6011 months ago

      Commenting well is a highly advanced skill. I generally prefer no comments on code since it’s less likely to confuse people and I’ll merrily purge auto-doc comments and anything like

      // getId() returns an id

      That comment has negative value.

      • kubica
        link
        fedilink
        2411 months ago

        I can’t help it, I always get the mental image of hands clapping sarcastically when I see something like that.

      • Platypus
        link
        fedilink
        English
        1011 months ago

        In my experience refactoring lots and lots of crappy code left by devs long gone, a dev who can write useful comments is by and large a dev who can write code clean and simple enough not to need them. If the code doesn’t have informative names and clear separation of concern, chances are a comment won’t help because the dev didn’t really know what they did that worked in the first place.

        • @MagicShel
          link
          1411 months ago

          Generally, yes. However I have been known to document exactly why I’m doing something incredibly stupid - because it’s required but a stupid third party library which, despite being awful, is still better than implementing it myself as a refactor.

        • Bappity
          link
          fedilink
          English
          311 months ago

          a dev who can write useful comments is by and large a dev who can write code clean and simple enough not to need them.

          my boss is great in this regard and also always has to keep reminding us to write unit tests 😅

      • 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.

      • Solar Bear
        link
        fedilink
        English
        611 months ago

        I write a lot of fairly simple scripts in Bash and PowerShell that should be easily understood by anybody else with moderate experience in the language, but I leave a lot of obvious comments because my coworkers don’t write any code and are extremely skittish about my automations. I add them basically to quell their fears.

        • @odium
          link
          911 months ago

          Why are coworkers who don’t write any code in the codebase?

          • Solar Bear
            link
            fedilink
            English
            7
            edit-2
            11 months ago

            These are scripts that manage stuff on a few hundred user endpoints and a few servers. They were doing basically everything manually until I got here, and the only way I could get them on board with my slow introduction of automation is to let them see it. I have to ensure things don’t get too long, complex, or hard to explain, or they start getting nervous.

      • oce 🐆
        link
        fedilink
        411 months ago

        I’d rather teach people to comment well through my reviews. Much easier to understand two lines of well written function description in English than 20 lines of code.

    • @[email protected]
      link
      fedilink
      411 months ago

      Yeah well now we have git copilot where your comments include AI suggestions.

      Now I have TONS more comments