• @jaybone
        link
        -32 months ago

        You mean autistic.

          • @jaybone
            link
            02 months ago

            And who updates that documentation three months later when a bug gets fixed or a new requirement get implemented?

            • @[email protected]
              link
              fedilink
              22 months ago

              The person who changed the code, it’s just ordinary maintenance. The comments may not execute, but I submit they are as much a part of the program as the executable code. Maybe over time those comments are condensed, or even removed; no different than any other refactoring or cleanup.

    • @BenLeMan
      link
      132 months ago

      Yup, my first thought as well. While those days are thankfully over, those braindead BIOS “help” messages remain etched into my mind forever.

      • @[email protected]
        link
        fedilink
        English
        62 months ago

        Are the recent ones any better? I got a gigabyte b660m for 12th gen intel and it’s really bad at that. Had to look up a lot to figure out things.

        • @BenLeMan
          link
          32 months ago

          Maybe it’s an ASUS thing but both my current and previous boards have been pretty good with the help texts.

          • @[email protected]
            link
            fedilink
            2
            edit-2
            2 months ago

            Snapmaker Luban is amazing with its help messages.

            Every setting in this 3D slicer is completely explained how the setting works, what the different options are, with pictures and even what every option is the most optimal in whatever situation.

            Too bad that it isn’t the best program unless you have a Snapmaker, and even then…

    • ඞmir
      link
      fedilink
      42 months ago

      Love having to enable “support for sleep state 5” to turn off USB power when the PC is off

  • @SlopppyEngineer
    link
    1282 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.

    • @[email protected]
      link
      fedilink
      1332 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
        942 months ago

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

        • ddh
          link
          fedilink
          English
          412 months ago

          // narrator: the reason was management

        • @NotMyOldRedditName
          link
          35
          edit-2
          2 months ago
          // I told them I'd do this but only if they gave me time next sprint to fix it  - 12-03-1997
          
          • @[email protected]
            link
            fedilink
            English
            152 months ago

            [flashbacks to the backlog being wiped out because “the client already signed off on the release”]

      • @ChickenLadyLovesLife
        link
        English
        122 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
          22 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
            link
            English
            32 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
      672 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
      162 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
      link
      122 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
        12 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

    • tiredofsametab
      link
      fedilink
      12 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>”.

  • @[email protected]
    link
    fedilink
    1082 months ago
    /*
     * Gets stupidFuckingInteger
     *
     * @returns stupidFuckingInteger
    */
    public double getStupidFuckingInteger() {
        return stupidFuckingInteger;
    }
    
    
  • katy ✨
    link
    fedilink
    74
    edit-2
    2 months ago

    //@TODO document this function later

    15 years later

    • @[email protected]
      link
      fedilink
      72 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

  • Martin
    link
    fedilink
    702 months ago

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

    • @[email protected]
      link
      fedilink
      English
      58
      edit-2
      2 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
        152 months ago

        Absolutely, although I see that as part of why

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

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

      • @[email protected]
        link
        fedilink
        English
        42 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.”

    • @calcopiritus
      link
      282 months ago

      Inline comments yes.

      Function/Class/Module doc comments should absolutely explain “what”.

      • Martin
        link
        fedilink
        82 months ago

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

        • @[email protected]
          link
          fedilink
          English
          62 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.

      • @myplacedk
        link
        12 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.

    • azdle
      link
      fedilink
      English
      52 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.

      • Martin
        link
        fedilink
        1
        edit-2
        2 months ago

        If you know how the code does something, you also know what it does.

  • ImpulseDrive42
    link
    622 months 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.

    • @[email protected]
      link
      fedilink
      392 months ago

      Code should always by itself document the “how” of the code, otherwise the code most likely isn’t good enough. Something the code can never do is explain the “why” of the code, something that a lot of programmers skip. If you ever find yourself explaining the “how” in the comments, maybe run through the code once more and see if something can be simplified or variables can get more descriptive names.

      For me, that’s what was originally meant with self-documenting code. A shame lazy programmers hijacked the term in order to avoid writing any documentation.

      • @ChickenLadyLovesLife
        link
        English
        152 months ago

        lazy programmers

        I don’t think they’re lazy, I think they’re not good writers. Not being able to write well is very common among programmers (not having to communicate with written language is one reason a lot of people go into coding) and in my experience the Venn diagrams for “not a good writer” and “thinks comments are unnecessary” overlap perfectly.

        • @[email protected]
          link
          fedilink
          12 months ago

          And isn’t it such a dangerous overlap! The coder whose writing (in their native language) is unclear, repetitive, convoluted, or hard to follow too often produces code with the same qualities. It’s even worse when the same coder believes “code is self-documenting” without considering why. Code self-documents with careful and deliberate effort, and in my experience, it is the really good writers who are most capable of expressing code in this way.

    • @Vigge93
      link
      28
      edit-2
      2 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
        link
        22 months ago

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

        • @Vigge93
          link
          22 months ago

          As long as it’s maintained. Wrong documentation can often be worse than no documentation.

    • ඞmir
      link
      fedilink
      112 months ago

      Code is not self documenting when decision trees are created based on some methodology that’s not extremely obvious

    • Ephera
      link
      fedilink
      11
      edit-2
      2 months ago

      In my opinion, it strongly depends on what you’re coding.

      Low-level code where you need to initialize array indices to represent certain flags? Absolutely comment the living shit out of that. → See response.
      High-level code where you’re just plumbing different libraries? Hell no, the code is just as easily readable as a comment.

      I do also think that, no matter where you lie in this spectrum, there is always merit to improving code to reduce the need for documentation:

      • Rather than typing out the specification, write a unit/integration test.
      • Rather than describing that a function should only be called in a certain way, make it impossible to do it wrongly by modelling this in your type system.
      • Rather than adding a comment to describe what a block of code does, pull it out into a separate function.
      • Rather than explaining how a snippet of code works, try to simplify it, so this becomes obvious.

      The thing with documentation is that it merely makes it easier to learn about complexity, whereas a code improvement may eliminate this complexity or the need to know about it, because the compiler/test will remember.

      This does not mean you should avoid comments like they’re actively bad. As many others said, particularly the “why” is not expressable in code. Sometimes, it is also genuinely not possible to clean up a snippet of code enough that it becomes digestable.
      But it is still a good idea, when you feel the need to leave a comment that explains something else than the “why”, to consider for a moment, if there’s not some code improvement you should be doing instead.

      • @[email protected]
        link
        fedilink
        42 months ago

        Hard disagree on your first point. Name the flags with descriptive name, move this initialisation to a function, and there you go, self-documented and clear code.

        • @[email protected]
          link
          fedilink
          32 months ago

          I’m with you but sometimes you don’t have the chance in low level. Max you can do is create local variables just so the bits you’re XORing are more obvious. And whenever you’re working with something where that’d be wasteful and the compiler doesn’t rid if it, you’re better off with comments (which you need to maintain, ugh)

        • Ephera
          link
          fedilink
          22 months ago

          Hmm, maybe my opinion is just shit in that regard. I don’t code terribly much low-level, so I’m probably overestimating the complexity and underestimating the options for cleaning things up.
          That was kind of just a random example, I felt like there were many more cases where low-level code is complex, but I’m probably basing this off of shitty low-level code and forgetting that shitty high-level code isn’t exactly a rarity either.

    • @[email protected]
      link
      fedilink
      112 months ago

      Have you ever worked in a place where every function/field needed a comment? Most of those comments end up being “This is the <variable name>, or this does <method name>”. Beyond, being useless, those comments are counter productive. The amount of screen space they take up (even if greyed out by the IDE) significantly hurts legability.

      • @Alexstarfire
        link
        02 months ago

        And a good IDE let’s you hide it so… what is your point?

        • @[email protected]
          link
          fedilink
          English
          42 months ago

          The issue with having mandatory useless comments is that any actually useful comments get lost in the noise.

          • @Alexstarfire
            link
            32 months ago

            I get what you’re saying. Perhaps I just haven’t had too many variables and such that have had such comments. VsCode shows the comments on hover when you’re in other parts of the code base. Which makes most any comment useful because something that is obvious in one part of the code isn’t immediately obvious in another. Though, that necessitates making comments that actually help you figure that out.

    • @[email protected]
      link
      fedilink
      102 months ago

      Good code is self documenting as in you don’t need to describe what it is doing and it is clear to read. Whoever says that and isn’t just repeating what they heard understands that whenever you are doing something not explicit in the code it should be on a comment.

      Workarounds and explaining you need to use this structure instead of another for some reason are clear examples, but business hints are another useful comment. Or sectioning the process (though I prefer descriptive private functions or pragma regions for that).

      It also addresses the hint that the code should be readable because you’re not going to have comments to explain spaghetti. Just a hint, doesn’t prevent it. Others also said it, comments are easier to get outdated as you don’t have the compiler to assist. And outdated comments lead to confusion.

    • @[email protected]
      link
      fedilink
      102 months ago

      Its definitely a balance. Good code shouldn’t need much commenting, but sometimes you have to do something for a reason that isn’t immediately obvious and that’s when comments are most useful. If you’re just explaining what a snippet does instead of why you’re doing it that way, there’s probably more work to be done.

    • @perviouslyiner
      link
      9
      edit-2
      2 months ago

      What they mean is that the variable names and function names are documentation.

      For example changing “for( i in getList() )” to “for( patient in getTodaysAppointments() )” is giving the reader more information that might negate the need for a comment.

    • @[email protected]
      link
      fedilink
      72 months ago

      I follow these simple rules and encourage my colleagues to do so

      1. If I’m just shuffling jsons, then yes, the code should be self documented. If it’s not, the code should be rewritten.

      2. If I implement some complex logic or algorithm, then the documentation should be written both to tests and in the code. Tests should be as dull as possible.

      3. If I write multithreading, the start, interruption, end, and shared variables should be clearly indicated by all means that I have: comment, documentation, code clearness. Tests should be repeated and waits should not be over 50ms.

    • Andromxda 🇺🇦🇵🇸🇹🇼OP
      link
      fedilink
      English
      72 months ago

      I absolutely agree, and I too hate this stupid idea of “good code documenting itself” and “comments being unnecessary”.
      I have a theory where this comes from. It was probably some manager, who has never written a single line of code, who thought that comments were a waste of time, and employees should instead focus on writing code. By telling them that “good code documents itself”, they could also just put the blame on their employees.
      “Either you don’t need comments or your code sucks because it’s not self-documenting”
      Managers are dumb, and they will never realize that spending a bit of time on writing useful comments may later actually save countless hours, when the project is taken over by a different team, or the people who initially created it, don’t work at the company anymore.

      • @ChickenLadyLovesLife
        link
        English
        62 months ago

        I’ve never had a manager that was even aware of the comments vs. no comments issue. If I ever had, I would have just told them that a lack of comments makes the original coder harder to replace.

    • @[email protected]
      link
      fedilink
      7
      edit-2
      2 months ago

      I actually agree that “good enough” code can be self-documenting, but it isn’t always enough to achieve my goal which is to make the code understandable to my audience with minimal effort. With that goal in mind, I write my code as I would write a technical document. Consider the audience, linear prose, logical order, carefully selected words, things like that… In general, I treat comments as a sort of footnote, to provide additional context where helpful.

      There are limits to self-documenting code, and interfaces are a good example. With interfaces, I use comments liberally because so many of the important details about the implementation are not obvious from the code: exactly how the implementation should behave, expected inputs and outputs under different scenarios, assumptions, semantic meaning, etc. Without this information, an implementation cannot be tested or verified.

    • @[email protected]
      link
      fedilink
      12 months ago

      I have worked on larger older projects. The more comments you have, the larger the chance that code and comment diverge. Often, code is being changed/adapted/fixed, but the comments are not. If you read the comments then, your understanding of what the code does or should do gets wrong, leading you on a wrong path. This is why I prefer to have rather less comments. Most of the code is self a explanatory, if you properly name your variables, functions and whatever else you are working with.

    • @[email protected]
      link
      fedilink
      12 months ago

      One example for self documenting code is typing. If you use a language which enforces (or at least allows, as in Python 3.8+) strong typing and you use types pro actively, this is better than documentation, because it can be read and worked with by the compiler or interpreter. In contrast to documenting types, the compiler (or interpreter) will enforce that code meaning and type specification will not diverge. This includes explicitly marking parameters/arguments and return types as optional if they are.

      I think no reasonable software developer should work without enforced type safety unless working with pure assembler languages. Any (higher) language which does not allow enforcing strong typing is terrible.

  • Johanno
    link
    fedilink
    452 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…

    • @jas0n
      link
      552 months ago

      Lol leave. That is so many levels of braindead.

        • @jaybone
          link
          52 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.

          • @[email protected]
            link
            fedilink
            English
            22 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.

    • @jaybone
      link
      82 months ago

      // this line increments the value of i by 1

      i++;

    • @[email protected]
      link
      fedilink
      English
      32 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

        • @[email protected]
          link
          fedilink
          English
          62 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

          • @[email protected]
            link
            fedilink
            72 months ago

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

            • @[email protected]
              link
              fedilink
              English
              7
              edit-2
              2 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

          • AlexanderESmith
            link
            fedilink
            62 months ago

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

  • @nikaaa
    link
    182 months ago

    Good code is self-explanatory. You should only comment your code if it does something unexpectedly complicated.

    That being said, it’s always a good idea to write a manual, about how to use the code. Don’t document how it works, because those who can code will understand it anyways, and those who can’t, have no need to understand it.

    • @[email protected]
      link
      fedilink
      342 months ago

      Good code is self-explanatory. You should only comment your code if it does something unexpectedly complicated.

      The code shows what is being done. The comments should explain the why.

      • Pasta Dental
        link
        fedilink
        14
        edit-2
        2 months ago

        Yes. This 1000x. I hate it at work when I come across code that was written 3 years ago that has literally no traces of why it’s there and a quick summary of what it does. Especially because that code is always the most abbreviated spaghetti you’ve ever seen. People should stop thinking (their) code documents itself because 99.999% of programmers cannot do it right.

        I really like the Google way of coding: assume the person reading the code is the most 1337 programmer ever, BUT that this person knows absolutely nothing about the project

        • @[email protected]
          link
          fedilink
          72 months ago

          Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.

      • @[email protected]
        link
        fedilink
        112 months ago

        This is something a lot of people don’t seem to understand. Even if code is self-explanatory, I want to know why it was designed that way.

        I’ve fixed bugs where the fix was only a one line change, but it was extremely difficult to figure out, so I left a 10ish line comment above it explaining why it has to be done that way.

    • @[email protected]
      link
      fedilink
      132 months ago

      Hard disagree. It’s a lot easier and faster to understand a function that is prefaced with a small line of text explaining what it does rather than trying to figure it out yourself.

      It’s not about whether you can understand the code or not, it’s about efficiency and clarity.

      • Aurelius
        link
        72 months ago

        Yeah, just 15 seconds and jot down a comment. Whenever I’m even hesitant, I just leave a comment. Doesn’t hurt anything and it can always be removed if not needed

        Easier to remove later rather than add it after the fact

      • @Aux
        link
        -12 months ago

        Hard disagree - that’s just dumb:

        // Calculates tax
        function calculateTax() { }
        
        • @[email protected]
          link
          fedilink
          10
          edit-2
          2 months ago

          Hard disagree - that’s very helpful:

          // Calculates Personal Income Tax by formula from section 1.2.3 of tax code. Other taxes like VAT are not calculated.
          function calculateTax() { }
          
          • @Aux
            link
            -42 months ago

            If it calculates personal income tax, just call calculatePersonalIncomeTax.

              • @Aux
                link
                02 months ago

                Add a flag.

              • @[email protected]
                link
                fedilink
                32 months ago

                I’m a new developer. Is that referring to page 123 of the in-house documentation? Version 12.3 of the code? I have no clue.

                You’d have to call it something like calculatePersonalIncomeTaxPerTaxCodeSection1_2_3, but I get exhausted just looking at that. There comes a point where the cognitive work of reading crazy long camel case names is more trouble than it’s worth.

                An explanation of what specification a function was written to implement is a perfectly appropriate comment. Could be improved by a direct link where possible. But it’s worth noting what that comment isn’t doing - specifying any implementation details. For that, I really can just read the code.

              • @Aux
                link
                12 months ago

                Yeah, why not?

      • @[email protected]
        link
        fedilink
        -12 months ago

        If done right, the “what it does” is in the method name. If your method is too complicated to summarize in its name, chances are good you should split it up or extract parts of it.

    • @TORFdot0
      link
      English
      22 months ago

      This is true, but it’s easier and faster to parse plain English and so if I don’t adequately comment my code the first time. I will be commenting it when I have to return to it for whatever reason. Honestly the second round of commenting is more verbose and clearer than the function x does y style of comments I tend to make when coding the first time

    • tiredofsametab
      link
      fedilink
      22 months ago

      Asinine business logic can still make some things very hard to read and digest no matter how well-planned and well-written it is (particularly if it is rushed by the business meaning that engineers don’t have time to do it well). As such, there are places where code can’t/won’t be self-documenting to a useful degree.

  • @Wild_Mastic
    link
    12
    edit-2
    2 months ago

    The code is self explanatory

    /s needed apparently

  • @Maalus
    link
    72 months ago

    How bad programmers comment their code. Good programmers don’t comment at all and let the code speak for itself, leaving commenting to some obscure and arcane implementation the coder left in after a week long binge on caffeine and gummy bears.

      • @Maalus
        link
        12 months ago

        Nah. It should be obvious by just looking at it in code. If it isn’t, you haven’t extracted single purpose methods out of it yet.

        • magic_lobster_party
          link
          fedilink
          2
          edit-2
          2 months ago

          Just having clear and concise variable names often goes a long way. Avoid using abbreviations.

          Breaking out the code into functions helps limit the number of variables within a scope, which makes it easier to name them.

    • BombOmOm
      link
      English
      11
      edit-2
      2 months ago

      Code should absolutely speak for itself. But the occasional comment is still good to explain the ‘why’ of the code when the why isn’t very obvious, often due to a niche requirement. Also any time you have to break out a hack, that needs comments up the ass, what was the bug, what URL did you find the fix at, why does this hack work, etc etc. It’s very satisfying to go back and remove those hacks after they are no longer needed, often because the underlying technology fixed the bug that had to be hacked around.

      • @Maalus
        link
        22 months ago

        Yeah, hence me mentioning the arcane code nobody knows what it does.

      • @NotMyOldRedditName
        link
        2
        edit-2
        2 months ago

        It definitely feels great when I get to remove the

        //hack abc due to bug in library xyz version 1.4.5, issue tracker says it’s fixed in 1.5.0. - link

    • magic_lobster_party
      link
      fedilink
      6
      edit-2
      2 months ago

      This is the truth. In my experience, the people who often writes comments are also writing the most incomprehensible code.

      Comments are frequently getting outdated as well, so they’re not in great help understanding the code either.

      • Codex
        link
        42 months ago

        I was rewriting some old code of mine and ended up stripping out the comments. I kept reading them instead of the code, which I had been changing, and they were irrelevant. (I added new comments back in, though a big reason to rewrite was to make the code more self-explanatory.)