• Johanno
    link
    fedilink
    499 months ago

    I write such comments because I have to.

    Company policy.

    Also we have to specify every line of code and what it should do…

        • @jaybone@lemmy.world
          link
          fedilink
          59 months ago

          Sometimes I think after i retire, I should teach. In the hopes that i could inspire people to write good code, instead of a lot of the garbage i see in the industry. This comment makes me sad.

          • @MystikIncarnate@lemmy.ca
            link
            fedilink
            English
            29 months ago

            I just want to be clear, this was like highschool cs classes. I took things a bit more seriously in college.

            I never wrote messy code or illogical code, or any code that didn’t work. We were learning C++ in those days and if you know anything about C++, you can basically cram an entire program into a single line. You can also do some shorthand stuff for calculations and updates to variables… So while the class was instructed to use whitespace and comments and update variables like “var = var + #” I would do var += #… I wouldn’t comment it, mainly out of hubris.

            I was pretty good at it but I was lazy as all hell with it.

    • @ulterno@lemmy.kde.social
      link
      fedilink
      English
      49 months ago

      I feel like I am going to have to do the same thing in the end, to get my hand-over accepted.
      Should I just copy the line of code and make a comment next to it with:

      // It does <paste line of code>
      

      CC BY-NC-SA 4.0

        • @ulterno@lemmy.kde.social
          link
          fedilink
          English
          79 months ago

          Not every. The quick, very-low effort ones, I just leave.

          Why:
          I saw another post with “Anti Commercial AI License”, then wen on to read the license and went, “Neat!”.

          • It makes it easier for anyone to decide what to do if they want to use my comment/post (in cases where it actually has something useful)
          • It makes life just a bit harder for people data-mining for AI
            • That way, some data entry worker will probably ask for a raise and probably even get it and maybe some entrepreneur going “AI everywhere!” will think twice.
            • Or there will be a chatbot spouting “Anti Commercial AI License” or “CC By-NC-SA” in their answer text, which would be hilarious.

          CC BY-NC-SA 4.0

          • AlexanderESmith
            link
            fedilink
            69 months ago

            It’s cute that you think data miners give a fuck about the license of anything they scrape.

          • @communism@lemmy.ml
            link
            fedilink
            79 months ago

            How are you inserting your signature? is it manually? Do you have some kind of keyboard shortcut to insert it?

            • @ulterno@lemmy.kde.social
              link
              fedilink
              English
              7
              edit-2
              9 months ago

              For now, I have just saved it in my clipboard application, so I copy-paste.
              When it goes out of history, I just open a file, where I have saved it and copy from there. So it’s pretty crude.

              I was hoping that either the KDE Social web interface would add a “Signature” feature or I would pick some Lemmy application that would allow that, but for now it’s just this.

              Perhaps, if I feel like it’s being too frequent, I may set a compose key for it.

              CC BY-NC-SA 4.0

  • KillingTimeItself
    link
    fedilink
    English
    -10
    edit-2
    9 months ago

    this is why i very rarely comment with descriptive comments. If you’re reading my code and don’t understand what it is, even with how shit it is, you have no business reading whatever fucking crackpot shit im writing.

        • @potustheplant@feddit.nl
          link
          fedilink
          39 months ago

          Doesn’t matter. Even if it’s your code, you might revisit something you made months or a year after doing it and having comments will speed up your work. It’s a very basic good practice.

          • KillingTimeItself
            link
            fedilink
            English
            09 months ago

            i do have comments, for some things, but there are a lot of “commenting” standards that are just shit. I find i don’t care what the actual piece of code is doing, i care more about it’s place in the rest of the code, and i’d much rather have “anti comments” instead.

  • @SlopppyEngineer@lemmy.world
    link
    fedilink
    1319 months 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.

    • tiredofsametab
      link
      fedilink
      19 months ago

      I was porting our old code from PHP to Go at a previous company. I laughed as I copied my then-six-year-old comment “I’m promised by xxxxx that this is a temporary measure <link to slack convo>”.

    • @conciselyverbose@sh.itjust.works
      link
      fedilink
      1379 months 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.

      • kubica
        link
        fedilink
        969 months ago

        // I'm not really that dumb, there is a reason.

      • @ChickenLadyLovesLife@lemmy.world
        link
        fedilink
        English
        139 months ago

        I spent a year making my company’s iOS apps accessible (meaning usable for the blind and people with vision disabilities). I had to do a lot of weird shit either because of bugs in Apple’s VoiceOver technology or because of the strange way in which our code base was broken up into modules (some of which I did not have access to) and I would always put in comments explaining why I was doing what I was doing. The guy doing code review and merges would always just remove my comments (without any other changes) because he felt that not only were comments unnecessary but also they were a “code smell” indicating professional incompetence. I feel sorry for whoever had to deal with that stuff at a later point.

        • lad
          link
          fedilink
          English
          29 months ago

          Well, this is shitty

          I hope the reviewer did not also squash commits, and the next programmer would be able to at least dig what was there.

          Doing changes after some rockstar dev implemented some really complex service, but left no clues as to what does what is so frustrating, and I can never be sure that I don’t break anything in a different place completely

          • @ChickenLadyLovesLife@lemmy.world
            link
            fedilink
            English
            49 months ago

            I meant to say commits and not merges, and yes he removed the comments before committing. It made no difference in long run because every new release broke all the accessibility stuff anyway. It’s amazing how little developers can be made to care about blind people - almost as little as managers. The only reason my company cared at all was they were facing million-dollar-a-month fines from the FCC.

    • Trailblazing Braille Taser
      link
      fedilink
      689 months 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.

    • recursive_recursion [they/them]
      link
      fedilink
      English
      179 months ago

      this seems like a great idea as it provides proof in writing just in case the stakeholder complains later on about the thing you implemented at their request

    • @jaybone@lemmy.world
      link
      fedilink
      139 months ago

      That’s actually the perfect comment, because if anyone ever comes back to fuck with you about it, it’s explained right there. Then you turn it right back around on management and watch them run around like chickens with their heads cut off.

      • lad
        link
        fedilink
        English
        19 months ago

        Out management used to tell us, that even if head of department had committed to doing something some way, there’s no way or need to hold them accountable. It’s just that situation has changed, and nobody should bat an eye.

        To be fair, they also did not pressure us much for the missed deadlines or missing features, because it was indeed the result of the situation described in the first paragraph

  • Martin
    link
    fedilink
    749 months ago

    Comments should explain “why”, the code already explains “what”.

      • @myplacedk@lemmy.world
        link
        fedilink
        19 months ago

        I agree.

        I usually think of that as documentation, not comments.

        But even so, the code should say what it does, with a good name. The documentation adds details.

      • Martin
        link
        fedilink
        89 months ago

        You are absolutely right. It was inline comments I had in mind.

        • @MystikIncarnate@lemmy.ca
          link
          fedilink
          English
          69 months ago

          I don’t code, at best I script. I’m a sysadmin, not a dev, so I play around in PowerShell mostly.

          I just started to naturally do all of this. Not because I was taught to, but because I’ve written too many scripts that I later looked at, and thought, WTF is going on here… Who tf wrote this? (Of course it was me)…

          So instead of confusing my future self, I started putting in comments. One at the beginning to describe what the file name can’t, and inline comments to step me through what’s happening, and more importantly why I did what I did.

          The sheer number of comments can sometimes double the number of lines in my script, but later when I’m staring into the abyss of what I wrote, I appreciate me.

    • azdle
      link
      fedilink
      English
      59 months ago

      Unless you’re working with people who are too smart, then sometimes the code only explains the how. Why did the log processor have thousands of lines about Hilbert Curves? I never could figure it out even after talking with the person that wrote it.

    • @smeg@feddit.uk
      link
      fedilink
      English
      63
      edit-2
      9 months ago

      The allowable exception is when the what is a what the fuck, as in you had to use a hack so horrible that it requires an apology comment

      • Martin
        link
        fedilink
        159 months ago

        Absolutely, although I see that as part of why

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

      • @bleistift2@sopuli.xyz
        link
        fedilink
        English
        49 months ago

        Describing the what also helps when you dabble in a new technology or little-used technology. It helps to explain to yourself what you’re doing and it helps in onboarding. “Hey, newbie, there’s a function in XYZ module that’s extensively documented. Look there for guidance.”

      • lad
        link
        fedilink
        English
        59 months 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

  • katy ✨
    link
    fedilink
    78
    edit-2
    9 months ago

    //@TODO document this function later

    15 years later

    • @Shoe@lemm.ee
      link
      fedilink
      89 months ago

      Have reviewed 16 year old code for a very well known company in the last week with this exact comment peppered throughout, alongside delightfully helpful comments like:

      // do not delete or change this it just works

      // TODO temporary fix added 12/09/11 to fix incident must be removed ASAP

      // CAUTION this returns false here instead of true like it normally does, not sure why

      // if true then matched to valid account not is true

  • @zerofk@lemm.ee
    link
    fedilink
    3
    edit-2
    9 months ago

    Our code base is filled with “//constructor”, “//destructor”, “//assignment”, or the ever enlightening “Foo GetFoo(); // GetFoo”.

    This is not what they mean by self-documenting code.

  • At work we let Typescript and descriptive naming document our code. Only when something is a workaround or otherwise weird will we add comments. So far it has worked great for us.