• DreamButt@lemmy.world
    link
    fedilink
    English
    arrow-up
    111
    ·
    6 days ago

    Ngl that’s like baby levels of nasty code. The real nasty shit is the stuff with pointless abstractions and call chains that make you question your sanity. Stuff that looks like it’s only purpose was to burn the clock and show off a niche language feature. Or worse than that even is when the project you inherit has decade old dependencies that have all been forked and patched by the old team

    If all I had to worry about was organization and naming I’d be over the moon

    • dohpaz42@lemmy.world
      link
      fedilink
      English
      arrow-up
      62
      ·
      6 days ago

      Git commits with message saying “pushing changes” and there are over 50 files with unrelated code in it.

        • pinball_wizard@lemmy.zip
          link
          fedilink
          arrow-up
          21
          ·
          edit-2
          6 days ago

          “Fix for critical issue.”

          Followed by an equally large set of files in a commit with just the message:

          “Fixup”

          And then the actual fix turns out to be mixed in with “Start sprint 57 - AutoConfiguration Refactor” which follows “Fixup”

      • Black616Angel@discuss.tchncs.de
        link
        fedilink
        arrow-up
        3
        ·
        5 days ago

        In the past I had commit messages with change numbers from a system, that was no longer in use.

        So the commit just said “CH-12345“. It is the kind of annoying, where you can’t even really be mad at someone.

        • dohpaz42@lemmy.world
          link
          fedilink
          English
          arrow-up
          2
          ·
          5 days ago

          I put my ticket numbers in my tickets, but i also try to describe the change too (e.g. “Fix bug where xyz happens due to zyx action”). Also, atomic commits: commit only related changes.

          Yes, it takes longer to commit large changes, BUT you can easily merge the commits, and rollback only what needs to be rolled back.

    • Zos_Kia@lemmynsfw.com
      link
      fedilink
      arrow-up
      6
      ·
      6 days ago

      The real nasty stuff is not code it’s in proprietary blobs which can only be edited through proprietary software. The documentation is shit (because the editor also sells training) and there are no communities (because implementation specialists think having secrets is having an edge).

    • criss_cross@lemmy.world
      link
      fedilink
      arrow-up
      5
      ·
      6 days ago

      My favorite was an abstract class that called 3 levels in to other classes that then called another implementation of said abstract class.

      And people wonder why no one on our team ever got shit done.

    • Valmond@lemmy.world
      link
      fedilink
      arrow-up
      2
      ·
      6 days ago

      And hard casting onto the wrong class because a neat function lives in there (who will detect you did that and treat you a little different because you don’t have all the resuired data in that class instance) as a “quick fix”

    • merc@sh.itjust.works
      link
      fedilink
      arrow-up
      1
      ·
      5 days ago

      Even if the abstractions aren’t pointless, there’s a limit to how many levels of abstraction you can make sense of.

      I’ve seen some projects that are very well engineered, with nice code, good comments, well named variables and functions. But, the levels of abstraction and nesting get so deep that you forget why you were digging by the time you get somewhere relevant.

      What’s frustrating there is that you can’t blame someone else. It’s just a limit for how much your brain can contain.

  • AllNewTypeFace@leminal.space
    link
    fedilink
    arrow-up
    85
    ·
    6 days ago

    Even worse than there being no comments: the code is extensively commented, but its function has drifted from what the comments describe to the point where they are actively misleading.

  • Epzillon@lemmy.world
    link
    fedilink
    arrow-up
    30
    ·
    edit-2
    6 days ago

    Jesus i worked at exactly this kind of project once. The only other dev was also very hostile and protective of this position. He did not want me there in the slightest. Took about 6 months before we cancelled the contract since this dude was just actively harrassing me in Teams DMs on the daily and he just ignored all my concerns regarding maintainability since “he could understand the code” and i was probably just “not experienced enough”.

    Don’t downplay what this does to your mental health. 5 years of workplaces like this and I’m now starting to see a therapist due to exhaustion disorder symptoms in my goddamn 20s. Take care our there!

    • tiramichu@sh.itjust.works
      link
      fedilink
      arrow-up
      11
      ·
      6 days ago

      So infuriating when you have some dickhead making themselves unfireable by intentionally convoluting the codebase and chasing out any other hire. And even worse when management bought into it and think the guy’s an actual irreplaceable genius.

      Probably even believes it himself. I hate narcissists.

  • GreenKnight23@lemmy.world
    link
    fedilink
    arrow-up
    34
    ·
    6 days ago

    longest file I have ever maintained contained 50,000 lines of code.

    fifty THOUSAND.

    forgive me for not weeping for 2000 lines.

    my advice, don’t fucking touch it. pull out as much functionality out of it into other things over time.

    there will come a day when you can throw it away. maybe not today, maybe not tomorrow… but some day.

    • meekah@discuss.tchncs.de
      link
      fedilink
      arrow-up
      25
      ·
      edit-2
      6 days ago

      Yeah, been there. The codebase I worked on also had a single method with 10k lines.

      The database IDs were strings including the hostname of the machine that wrote to the DB. Since it was a centralized server, all IDs had the same hostname. The ID also included date and time accurate to the millisecond, and the table name itself.

      Me: Mom, can we have UUIDs? Mom: We have UUIDs at home UUIDs at home: that shit

      • rbn@sopuli.xyz
        link
        fedilink
        arrow-up
        15
        ·
        6 days ago

        You should add the local weather forecast, a random fun fact and the canteen menu of the day to the key to make it more interesting to read.

    • Hotzilla@sopuli.xyz
      link
      fedilink
      arrow-up
      6
      ·
      edit-2
      6 days ago

      I was working on a project that had 100 000 line oracle database PL/SQL procedure that ordered a work order from subcontractor. It was just one single function. That was called by classic asp + visual basic COM component.

      Oh Lord, I get Vietnam flashbacks about it.

  • gingersight@programming.dev
    link
    fedilink
    English
    arrow-up
    17
    ·
    6 days ago

    Oh, it’s only the files that have over 2k lines of code? Hell, I’ll take that over what I’m dealing with now. I’ve got multiple FUNCTIONS that are over 2k lines. >:(

    • ripcord@lemmy.world
      link
      fedilink
      arrow-up
      15
      arrow-down
      1
      ·
      6 days ago

      Yeah, I dont see a big problem with files over 2000 lines in some cases, as long as things remain well writrej, organized, abstractd.

      One piece of garbage that I’ll never touch again hae most functions this size. One was 50,000 lines! Hundreds.of lines of if/else, half of the functions passed the same 60 arguments because he didn’t understand classes or even dictionaries, etc etc. And was used heavily.

      • PhilMcGraw@lemmy.world
        link
        fedilink
        English
        arrow-up
        2
        arrow-down
        1
        ·
        5 days ago

        Yeah, honestly overly splitting things up is worse sometimes, that’s how you end up in Java land. Any time you want to grok a specific function you end up down 30 abstracted code paths. Essentially need a compiler to unroll it all to actually see what it’s doing.

        • ripcord@lemmy.world
          link
          fedilink
          arrow-up
          1
          arrow-down
          1
          ·
          5 days ago

          Java was exactly the negative use case I was thinking of. Trying to track down the flow of things for code I don’t look at regularly drives me insane.

  • HugeNerd@lemmy.ca
    link
    fedilink
    arrow-up
    18
    arrow-down
    1
    ·
    6 days ago

    That’s what agentic AI is for! Your OS will figure out by itself what you are doing and weave together a shambolic rococo digital house of cards that will be not just undocumented but utterly incomprehensible.

    It’s fine, just get a 5GHz CPU with 48 cores, 1TB of DDR5 HBM super RAM, and maybe a few petabytes of storage (in the cloud in a flatpack Docker that runs on a VM), so that you can finally make that button blue.

      • HugeNerd@lemmy.ca
        link
        fedilink
        arrow-up
        6
        ·
        6 days ago

        Fucken right, get your agentic AI to get in touch with my agentic AI (with wire transfer deets)

  • ChickenLadyLovesLife@lemmy.world
    link
    fedilink
    English
    arrow-up
    18
    ·
    6 days ago

    There are no comments in the code

    At my last job, I was assigned to a project being run by a straight-out-of-college developer who felt that not only were comments unnecessary, they were actually a “code smell”, a sign of professional incompetence on the part of whoever added them. It’s an insane philosophy that could only appeal to people who have never had to take over an old codebase.

    • ipkpjersi@lemmy.ml
      link
      fedilink
      arrow-up
      13
      ·
      6 days ago

      I kind of get the idea that code should be self-documenting, but at the same time, there’s so many crazy business rules that comments are basically a necessity if nothing else other than to explain why in the hell the crazed mess that provides the required functionality for the business rules exists.

      • jjjalljs@ttrpg.network
        link
        fedilink
        arrow-up
        12
        ·
        6 days ago

        Yeah some comments are not useful

        # returns the value as a string
        return str(user.id)
        

        Some comments are

        # returns the user id as a string because ZenDesk's API throws errors if it gets a number.
        # See ticket RA-1037
        # See ZenDesk docs: https://etc/
        return str(user.id)
        
      • PonderingPotato@discuss.tchncs.de
        link
        fedilink
        English
        arrow-up
        6
        ·
        6 days ago

        That’s typically what people who advocate for less/no comments really mean. The code should self explain “what” it does, but if the “why” isn’t obvious (i.e. confusing business logic) nobody argues that you shouldn’t comment it. That’s how I’ve worked in every company I’ve been at (and all developers around me) from 50 person start ups to >2k people. It’s really common mentality with Ruby developers

        • JcbAzPx@lemmy.world
          link
          fedilink
          English
          arrow-up
          2
          ·
          6 days ago

          Anyone complaining about commenting should be forced to code in assembly for a while.

    • CodeBlooded@programming.dev
      link
      fedilink
      arrow-up
      7
      ·
      6 days ago

      Or, it appeals to people that have had had to take over an old codebase where the comments were all lies.

      “Code never lies. Comments sometimes do.”

      • ChickenLadyLovesLife@lemmy.world
        link
        fedilink
        English
        arrow-up
        4
        ·
        5 days ago

        It’s funny, the exact same logic applies to method and variable names. There’s no compiler that ensures that a method’s name accurately describes what the method does or ensures that a variable’s name accurately describes what the variable represents. Yet nobody ever says “you shouldn’t use descriptive method and variable names because they might be misleading”. And this is hardly academic: I can’t count the number of times I’ve run into methods that no longer do what the method name implies they do.

        And yet method and variable names are exactly what people mean when they talk about “self-documenting” code.

  • iegod@lemmy.zip
    link
    fedilink
    arrow-up
    18
    ·
    6 days ago

    I’ll get shit on for suggesting it but this is a great use case for AI: comment the code and generate some basic docs. Even if it’s wrong it’ll give you a sense of where to start looking for flows.

    • JcbAzPx@lemmy.world
      link
      fedilink
      English
      arrow-up
      3
      ·
      6 days ago

      Problem is, you won’t know what the AI screwed up until someone breaks everything.

  • Adalast@lemmy.world
    link
    fedilink
    arrow-up
    26
    ·
    6 days ago

    I literally told my boss that I was just going to rebuild the entire pipeline from the ground up when I took over the codebase. The legacy code is a massive pile of patchwork spaghetti that takes days just to track down where things are happening because someone, in their infinite wisdom, decided to just pass a dictionary around and add/remove shit from it so there is no actual way to find where or when anything is done.

    • themaninblack@lemmy.world
      link
      fedilink
      arrow-up
      9
      ·
      6 days ago

      FUCK. Triggers me. Just got let go from a place that had this problem and wouldn’t let me make any changes whatsoever. I didn’t even push hard.

    • Lightfire228@pawb.social
      link
      fedilink
      arrow-up
      5
      ·
      edit-2
      6 days ago

      I did this once

      I was generating a large fake dataset that had to make sense in certain ways. I created a neat thing in C# where you could index a hashmap by the type of model it stored, and it would give you the collection storing that data.

      This made obtaining resources for generation trivial

      However, it made figuring out the order i needed to generate things an effing nightmare

      Of note, a lot of these resource “Pools” depended on other resource Pools, and often times, adding a new Pool dependency to a generator meant more time fiddling with the Pool standup code

    • wols@lemmy.zip
      link
      fedilink
      arrow-up
      4
      arrow-down
      1
      ·
      6 days ago

      Side-rant:
      I rarely write Python code. One reason for that is the lack of type safety.
      Whenever I’m automating something and try to use some 3rd party Python library, it feels like there’s a good 50/50 chance that front and center in its API is some method that takes a dict of strings. What the fuck. I feel like there’s perhaps also something of a cultural difference between users of scripting languages and those of backend languages.

      What you described sounds so much worse though holy shit.

      • Adalast@lemmy.world
        link
        fedilink
        arrow-up
        2
        ·
        5 days ago

        Yeah, the new pipeline is based HEAVILY on object inheritance and method/property calls so there is a paper trail for ALL of it. Also using Abstract Base Classes so future developers are forced to adhere to the architecture. It has to be in Python, but I am also trying to use the type hinting as much as humanly possible to force things into something resembling a typed codebase.

  • explodicle@sh.itjust.works
    link
    fedilink
    English
    arrow-up
    15
    ·
    6 days ago

    I’ve been doing this for years at my current job. It has become a masterpiece of refactoring and comments. They weren’t even asking the right questions. I’m very proud of myself.

    So naturally, I’m about to get fired and have the whole thing redone by AI.

    • Shanmugha@lemmy.world
      link
      fedilink
      arrow-up
      2
      ·
      4 days ago

      Then re-hired for 3x salary to make it work again, I hope. Or just watch the company/project fail spectacularly

  • Tony Bark@pawb.social
    link
    fedilink
    English
    arrow-up
    29
    arrow-down
    2
    ·
    6 days ago

    I was part of project that scoffed at the idea documenting code. Comments were also few and far between. In retrospective, it really seemed like they wanted to give that elitist feel because everything reeked of wanting to keep things under wraps despite everything being done out in the freakin’ open.

  • madjo@feddit.nl
    link
    fedilink
    arrow-up
    17
    ·
    6 days ago

    ARGH this triggered a bit of PTSD for me…

    “We’re going to convert these COBOL applications to C#, and you need to test that the new application works exactly the same, including the same bugs as the old application.”
    “Ok, where’s the specifications and test reports of the old COBOL applications?”
    “They were lost to time, we don’t know where they are.”
    “Ok, so how are the developers going to write the C# code?”
    “They’re going to read the COBOL scripts and recreate them into C#, we advise you do the same.”

    Cue me spending a month trying to decypher the COBOL gobbledigook into inputs and outputs, and write testcases based on that. And after that month was up, and I had delivered my testcases, they told me that my services were no longer needed.

    • JcbAzPx@lemmy.world
      link
      fedilink
      English
      arrow-up
      1
      ·
      6 days ago

      I had delivered my testcases, they told me that my services were no longer needed.

      Gee, I wonder how all those specifications and test reports became “lost to time”…

      • Ephera@lemmy.ml
        link
        fedilink
        English
        arrow-up
        15
        ·
        6 days ago

        Pretty sure that knowing COBOL isn’t the hard part. It has relatively few language concepts.

        This lack of language concepts just makes it difficult to reason about it, so that’s what you’re getting a paycheck for. Well, and possibly also because it might take months to have a new dev figure out your legacy codebase, so it’s cheaper to keep the current dev by paying them competitive prices.

        • AngryCommieKender@lemmy.world
          link
          fedilink
          arrow-up
          12
          ·
          edit-2
          6 days ago

          Not quite. More like per 40 hour week with no overtime, but my father insists on having up to 20 hours a week of overtime he’s allowed to burn, so it’s kinda like $7,500 a week. He generally gets paid byweekly or monthly. Subcontractor and all that BS

      • Aganim@lemmy.world
        link
        fedilink
        arrow-up
        2
        ·
        5 days ago

        What? I make that kind of money by dabbling in Ansible, Python and Kubernetes. $5000 sounds pretty lowball for fairly niche knowledge like COBOL.

          • Aganim@lemmy.world
            link
            fedilink
            arrow-up
            2
            ·
            5 days ago

            I don’t know, but for me it was undiagnosed ADHD. 😋 Fortunately IT is one of the areas where lack of a degree isn’t a showstopper.

            • spicy pancake@lemmy.zip
              link
              fedilink
              English
              arrow-up
              2
              ·
              edit-2
              5 days ago

              i mean i recently did a contract gig updating a 6 year old legacy codebase in a language I’ve never used

              oh also I’ve barely coded anything in my life

              you guessed it, i used an LLM (as the contracter requested, but still…) ¯\_(ツ)_/¯

              so i keep waffling between “my (then) undiagnosed ADHD would have stunted my CS learning hard enough that I’d barely be any more knowledgeable than I am now anyway” and “despite it being a terrible fucking idea companies are going to try their damnedest to replace all software engineering with vibe coding”

              so i end up back at “at least i have a degree in pipetting and can go get a $20/hr job moving small volumes of liquid back and forth until pipetting robots become cheaper than me”

  • Unimalion @sh.itjust.works
    link
    fedilink
    arrow-up
    20
    ·
    6 days ago

    I just inherited my first codebase a few months ago. It’s like this everywhere and original developer was fired, so what should sometimes be a simple fix turns into a full day of finding what needs to change. Any recommendations on fixing/maintaining code like this or should I just make it the next person’s problem?

    • Lightfire228@pawb.social
      link
      fedilink
      arrow-up
      27
      ·
      edit-2
      6 days ago
      • if it’s not in git / SVC, add it as is. Create a “refactor” branch, and liberally use commits

      • Treat it like a decompilation

      Figure out what something does, and rename it (with a stupidly verbose name, if you have to). Use the IDE refactor tools to rename all instances of that identifier

      • Take a function, figure out what it does, and refactor it in a way that makes sense to you

      • Use the editor’s diff mode to compare duplicate code, extract out anything different into a variable or callback, and combine the code into a function call. Vscode’s “select for compare” and “compare with selected” are useful for this

      • Track what you’re doing / keep notes in something like Obsidian. You can use [[Wikilinks]] syntax to link between notes, which lets you build a graph structure using your notes as nodes

      • be cognizant of “Side Effects”

      For example, a function or property, or class might be invoked using Reflection, via a string literal (or even worse, a constructed string). And renaming it can cause a reflective invocation somewhere else random to fail

      Or function or operator overloading/overiding doing something bizarre

      Or two tightly coupled objects that mutate each other, and expect certain unstated invariants to be held (like, foo() can only be called once, or thingyA.len() must equal thingyB.len()

      • write tests if you can, either using a testing framework or custom Python scripts

      You can use these to more thoroughly compare behavior between the original and a refactor

      • Lightfire228@pawb.social
        link
        fedilink
        arrow-up
        13
        ·
        6 days ago
        • if something feels too “heavy”, like it’s doing xml formatting, file manips, a db insert, and making coffee, all in a single class or function

        Separate out those “concerns”, into their own object/interface, and pass them into the class / function at invocation (Dependency Injection)

        • use “if guards” and early returns to bail from a function, instead of wrapping the func body with an if
        
        public Value? Func(String arg) {
          if (arg.IsEmpty()) {
            return null;
          }
          
          if (this.Bar == null) {
            return null;
          }
        
          // ...
          return new Value();
        
        
          /// instead of
        
          if (!arg.IsEmpty) {
            if (this.Bar != null) {
              // ...
              return new Value();
            }
          }
        return null;
        }
        
        • jjjalljs@ttrpg.network
          link
          fedilink
          arrow-up
          2
          ·
          6 days ago

          Lowering indent levels is nice in functions. Early returns mean you don’t have to think as much. “If it got here, I know foo isn’t null because it already would have returned”.

        • Clay_pidgin@sh.itjust.works
          link
          fedilink
          English
          arrow-up
          1
          ·
          6 days ago

          I always feel bad about putting little ifs at the top of functions. Is it not bad practice? I like them because they’re simple to implement modify and read, but I have this voice telling me I need to make things more impressive.

          • Lightfire228@pawb.social
            link
            fedilink
            arrow-up
            2
            ·
            5 days ago

            Never make things more “impressive”

            Make them more comprehensible

            Reduce the cognitive load required to understand and reason about a piece of code. Honestly, the more you can express complicated ideas simply, the more impressive you are

          • Jankatarch@lemmy.world
            link
            fedilink
            arrow-up
            2
            ·
            edit-2
            6 days ago

            I started putting a helpful comment above the ifs as a seperator to cope with that.

            public Value? Func(String arg) { 
              // Sanitize.
              if (arg.IsEmpty()) return null; 
              if (this.Bar == null) return null; 
              // Get [that] and/or do [this].
              var foo = this.baz.foo;
              ...
              return new Value();
            }
      • Clay_pidgin@sh.itjust.works
        link
        fedilink
        English
        arrow-up
        1
        ·
        6 days ago

        I use sentences as variable names sometimes, because I necessarily end up with lots of similar-sounding variables or functions.

        List_of_foo_dicts = Get_foo_from_bar_api()

    • mad_lentil@lemmy.ca
      link
      fedilink
      English
      arrow-up
      4
      ·
      edit-2
      5 days ago

      You’re going to want to follow the “campsite rule” everywhere you go, and also sneak in positive refactors into your feature changes (if business is not willing to commit time to improving the maintainability of the codebase).

      Read up on good software design principles. I don’t know you experience level, but for instance, everyone agrees that appropriate abstraction, and encapsulation make code easier and more enjoyable to work with, and will let you run tests on isolated sections of the code without having to do a full end-to-end testsuite run.

      Having tests that you trust, especially if they execute quickly, will increase your “developer velocity” and let you to code fearlessly–knowing that your changes are reasonably safe to deploy. (Bugs and escaped defects will happen, but you just fix them and continue on.)

      Good luck!