• cbazero
      link
      fedilink
      arrow-up
      15
      arrow-down
      2
      ·
      9 hours ago

      You dont. Thats why you write code that explains itself. For higher level info you write documentation.

        • Maalus@lemmy.world
          link
          fedilink
          arrow-up
          3
          arrow-down
          1
          ·
          54 minutes ago

          The only moment you write comments is when you are doing something extremely weird for a specific reason that will not be immediately obvious and you want to warn the person doing a refactor in the future. In any other case, writing self documenting code is the way. If you are unable to do that, then your code needs to be rewrtitten.

          • ruekk@lemm.ee
            link
            fedilink
            English
            arrow-up
            1
            ·
            1 minute ago

            Self documenting code is a myth as what’s self documenting to one person is not to the next. Code comments and process/workflow documentation is needed for a healthy codebase.

  • fubarx@lemmy.world
    link
    fedilink
    arrow-up
    83
    ·
    edit-2
    9 hours ago

    My first tech job out of college, I was told to go talk to “Dave,” the guru old-timey programmer and learn the lay of the land. He turned out to be this crotchety old guy, with low tolerance for idiots, but a soft spot for someone who actually paid attention.

    A few months in, I was told to go fix a feature in the company’s main product which was sold to power utilities. This was a MASSIVE code base, with a mix of C, C++, assembler, and a bit of Fortran thrown in. I spent a week poring through all the code trying to figure things out. Then I hit a mystery workflow that didn’t make sense.

    I walk over to Dave’s office and ask a specific question. Now, mind you, he had worked on this years ago, and had long moved on to new products. He leans back in his chair, stares at the ceiling, then without looking at the screen once tells me to go look at such and such file for such and such variable, and a list of functions that were related. I go back to my desk and damn if it wasn’t EXACTLY as he described.

    Now, I’m probably as old as he was then. I don’t remember what I wrote an hour ago. No matter what I build, I’ll always be in awe of Dave and what he could keep in his head.

    • Lemminary@lemmy.world
      link
      fedilink
      arrow-up
      19
      ·
      15 hours ago

      Alt theory: The guy you replaced failed miserably. Dave poked around but decided it wasn’t worth his time fixing. Instead, decided to look badass for the cameras and died a legend.

  • Ephera@lemmy.ml
    link
    fedilink
    English
    arrow-up
    48
    ·
    17 hours ago

    Which is why making code readable is so very important. Our juniors and students will think we’re ridiculous, when we spend a long time cleaning up some code or choosing the least misunderstandable name for a type. But you fuck that up and then others, as well as your future self, will be wasting many more minutes misunderstanding what your code does.

    • rockerface 🇺🇦@lemm.ee
      link
      fedilink
      arrow-up
      28
      ·
      15 hours ago

      I treat my future self a few months from now as a separate person who does not remember anything about why or what the specific code fragments do. And I’m grateful to my past self for doing the same.

      Plus, you never know when you need to actually delegate supporting a particular piece of a solution to another person.

      • homoludens@feddit.org
        link
        fedilink
        arrow-up
        7
        ·
        13 hours ago

        Write your code as if the next person that works with it is a violent psychopath who knows where you live.

  • bitwolf@sh.itjust.works
    link
    fedilink
    English
    arrow-up
    28
    ·
    16 hours ago

    Partially yes. But if I create something myself I can “revisit” the headspace of that portion very easily, like I walked into a room.

    Doesn’t work as well on codebases I don’t own fully though.

    • Ephera@lemmy.ml
      link
      fedilink
      English
      arrow-up
      9
      ·
      15 hours ago

      Yeah, which is why pairing works so well. Suddenly, you’ve got two people who were there when it was created and might know why certain design decisions were made.

  • some_guy@lemmy.sdf.org
    link
    fedilink
    arrow-up
    42
    ·
    18 hours ago

    This made me chortle. I remember when I first joined a dev team asking someone how many of something their section should be able to store:

    I don’t know, I’d have to look at the code.

    It was an eye opening moment. Very few people can keep everything in their head. I’ve met a couple. They were rockstars who were truly exceptional.

    • livingcoder
      link
      fedilink
      arrow-up
      21
      ·
      18 hours ago

      For me it all depends on how often a project changes. If it’s constantly in flux, I don’t bother remembering any of it because I might not be the last one who touched it. The more you try to remember everything, the more wrong you become due to the successive work of your coworkers.

  • wise_pancake@lemmy.ca
    link
    fedilink
    arrow-up
    23
    arrow-down
    2
    ·
    18 hours ago

    The people who say “the code is the documentation” totally misunderstood what that was supposed to look like

    • SchwertImStein@lemmy.dbzer0.com
      link
      fedilink
      English
      arrow-up
      2
      arrow-down
      1
      ·
      49 minutes ago

      a good code doesn’t require comments.

      Commenta should only exist to explain external requirement leading to a functionality being unexpected.

    • exu@feditown.com
      link
      fedilink
      English
      arrow-up
      6
      ·
      12 hours ago

      I’m also not a programmer, you’ll find my longest comments to explain why I’ve done some terrible mangling, what this does and how.

    • Ephera@lemmy.ml
      link
      fedilink
      English
      arrow-up
      26
      ·
      18 hours ago

      Spamming comments is rather controversial, especially in high-level languages. Problem is, they only show up in one place, so they’re just not very useful, but also have a high chance of becoming inaccurate over time. In particular when you spam them to explain relatively trivial stuff, people will stop reading them, meaning they won’t update them.

      The ‘what’ can be documented with meaningful variable/function names, log/error/assert messages and perhaps most importantly unit/integration tests (which should be understood like a specification that checks automatically that it’s applied correctly).

      Comments are indispensible for explaining the ‘why’, though, whenever that is not obvious.

      • rockerface 🇺🇦@lemm.ee
        link
        fedilink
        arrow-up
        7
        ·
        15 hours ago

        Yeah, there’s a balance. If you comment every row of your code, you aren’t naming things clearly. If you never comment, the context is always incomplete.

        • vaionko@sopuli.xyz
          link
          fedilink
          arrow-up
          3
          ·
          edit-2
          10 hours ago

          You don’t comment what something does, ir can clearly be seen from the code itself. You comment why you do it.

          • Gumby@lemmy.world
            link
            fedilink
            English
            arrow-up
            1
            ·
            1 hour ago

            “Clearly” is also subjective. What might be perfectly clear to me reading my own code may be really confusing to someone else, and vice versa. Especially if the person reading the code isn’t as familiar with the language as the person who wrote it, or if the code is using some syntactic sugar that isn’t super common, or plenty of other reasons.

            • vaionko@sopuli.xyz
              link
              fedilink
              arrow-up
              1
              ·
              57 minutes ago

              True. It’s more like there’s no need to comment an if statement with “checks if a is larger than b”

  • Spacehooks@reddthat.com
    link
    fedilink
    English
    arrow-up
    5
    ·
    15 hours ago

    The code is so convoluted the programmer has no idea how it works. Just tables and arrays references each other.