I'm sure it's about 5000 lines of extensive docstrings and notes that explain the assumptions, design choices, and trade-offs that were considered before it was developed.
but they often pay well. I'm right now staring at code that just doesn't do anything because it only checks properties of an object that never has any write access. Someone wrote it. Someone approved it. The company makes millions. At this point I just don't care anymore. I'll just copy paste it because I need the same thing in the other application and if that's what they want they get it.
lol, true. In my case a lot of the bugs can be fixed automatically by intellij because they are just very simple patterns of obvious bugs. Is AI even trained on such shitty code? And how could it do anything when there no no tests? It would face the same problems I do. I cant change anything because there would be no tests to verify that it still works. I wish I could rework a method of 13000 lines. At least I could do something. Instead, I sit here and do nothing because nobody seems to know the backend.
No doubt. When you have multiple files with thousands of lines, each of them calling functions from each other, and its multithreaded, and wondering how it even compiles. And that's just the Java half of a massive payment system, and the other half is written in Perl built by an acquired company and bolted on like some kinda Frankenstein. And then refactored that shit down to a proper SOA over eight years. Then you've really lived.
I have had these conversations before, and learned to just comment the old code and rewrite it without arguing with people that don't understand software engineering and asset value.
Manager: Can you patch this junior developed buggy mess?
It would be better to write it from scratch, it will take less time and work better.
Manager: No! you can't just ignore the precious work put into this buggy mess, by the junior employee that we fired. They spent like 8 months working on this. Just patch the 1-2 bugs to make it work.
I already looks at the code, there are more bugs than lines of code. It's worth nothing, actually just looking at the code is a net negative. I can just rewrite this in 4 work days.
Manager: No! we don't have any requirements written and don't know how it should work or what it needs to output, just fix the bugs.
I actually quite like Java, and spent a lot of time with it. I came to it after .NET and c# left me feeling "locked in". I'm all Rust these days, though, for years now.
I recently had a Java file that was like 500LoC and it was genuinely becoming impossible to manage, idk how people do this, how can you even keep that much context in your mind, and how can your computer keep it in RAM
Near the end of that whole 500LoC ordeal, my laptop was starting to grind to a halt just trying to provide autocomplete, I was coding blind then waiting half a minute for the computer to tell me if the code was even valid
I'd start by copying the function into another file and breaking it down into smaller ones. if you feel too lazy for it ask your favorite LLM to do it for you. They're usually not too bad at breaking down big functions.
I get that this can sometimes be helpful and tbh I don't know that language but that function starts off defining a bunch of types and helper functions so maybe start by externalizing those?
I have once tried to refactor a 60k function which was generated by simulink. When compiling that C file the compiler just gave a warning that all optimizations are disabled due to how large that function was. I split it to like 20 smaller functions so the compiler optimizations start working. The funny thing is that after benchmarking, the 60k unoptimized version was faster...
This is actually a much more solvable problem with AI. First thing I would do is have Claude write a shit ton of tests. Emphasize that the tests need to be small and self contained and tell Claude not to touch the existing code AT ALL.
Then when youβve reviewed the tests and they are all passing, just tell Claude to start refactoring. Itβs actually really good at this because even though the context is messy, itβs all there. Keeping 20K lines of code in context is not a big deal for an LLM even though itβs almost impossible for a human.
At least that function has an end, if you ever tried to debug code with 60 goto statements that lead to wildly different parts of other code, then you know you hit the peak of bad code
Hilarious but honestly, it's probably not that bad. Guaranteed you can create a separate file with the parts that make it work and then break it into bits little by little.
This gives you solid foundations for how to think about legacy code, and how to transform it over time. The very problems you identify are the keys for transformation. The key is to not get stuck in paralysis.
There are no tests, therefore it is brittle. Write tests. Tests are hard? Use "Extract Method" to pull out methods one by one, writing tests for each one. You'll find that testable code is cleaner code, better-designed code, more flexible code. You can apply these basic principles to everything. Things are in the front end that should be in the back end? "Extract Method" of front end business logic one by one into the back end. Add tests, rinse, repeat. The more you do, the better you get at it, the cleaner the code gets, the easier it gets. It's a discipline, but when you actually experience a transformation, you'll be hooked, too, and unwilling to work in shit shows ever again.
To take this to the next level, develop discipline to automate anything that slows you down. It may seem like you are dilly-dallying with side questions, but every time you automate your CI, reduce frictions in your development environment, create templates to bootstrap new projects, the more time you have to refactor code, the more opportunities you have to try out ideas, build projects you've always wanted to pursue. Basically, engineer your way out of drudgery, and don't ask permission to do it.
I took your advice and actually fed this to claude opus, was actually scary how well it worked, I don't feel too confident in it, but it's given me something to work with and gotten me some level of structure to work with.
Awesome. It takes some getting used to. Also, everyone goes through the 5 Stages of AI Acceptance, one of them being "Hold my beer", where you forget to be an engineer. Use it as a learning tool. Add one feature/refactor at a time. Have Claude explain what it did. Make Claude write tests. Don't be afraid to say, "Bullshit, this can/should be better", and iterate. You've still gotta be an engineer. Have fun!
Just keep extracting methods. Sometimes you have to merge them together or back to the original place when you have better understanding of that code. This is achievable.
Dude call me crazy but I would love that. Like the idea of doing that makes me excited. I absolutely live refactoring old code. I've taken Cobol and rewrote it as C# before. It must be what it feels like for those people who take really old artwork and clean the years of grime off of it and fix it up nice.
Aah my olden days. a legacy codebase with a single 40k VS crashing .CS file and a 35k sql containing xml, that I had to work with every tooling, autocomplete and code hint disabled (basically at that point visualstudio was a nicely themed notepad)
I never said it is 100% indication of vibe coding. The keyword is probably, might, and check if there is any indication, for example: AGENTS.md or CLAUDE.md. Read carefully, dumbass.
Not really vibe coding, because that is doing it blindly.
But it is a very good use case for using AI.
First ask what the function is doing, then ask to write tests. Check for coverage. Ask which parts can be illuminated. Ask which strategies are possible. Then give it instructions to do it. But do it part per part and keep track of your tests.
Basically it is how I would do it without AI but I give AI instructions to help me
This is how you produce viable software with AI. Step by step. No autonomous multi agent 8 hour blindfire shit. We are not there yet, at least not as consumers, but it still is already so much more potent than coding by hand, I wager to say no matter how insane your coding skills. It's just too fast already.
Some people would rather spend thousands on tokens in ralph loops instead of actually learning about what they are building. It's weird. Or maybe that's just a small, loud minority.
Sure, check out this bizare conversation I had with an LLM recently. The really scary thing: it worked. It finally performed an action it refused to do so over two hours before.
That of course the explains the cat emojis, somehow it remembered the "or else somebody kills a kitten" lore from the internet. But it does not explain why it finally executed something it didn't before. I was trying everything, including guided debugging "which tools do you see? are you using MCP? what does the tool description say? explain step by step to me our plan..." - and re-formulating my prompt multiple times. I finally was about to give up, so this was my last try, more out of frustration. And it worked.
268
u/PsychologicalLab7379 Mar 15 '26
SOLID left the chat.
438
u/AccomplishedLeave506 Mar 15 '26
Oof. That's not a function. That's an entire dev teams life story. Run away.
140
u/HappyToast__ Mar 15 '26
Double it and give it to the next person.
104
u/GianLuka1928 Mar 15 '26
That company is definetly huge red flag
46
u/thusman Mar 15 '26
I already get headache with files larger than 500 lines of code π
35
u/FortuneAcceptable925 Mar 15 '26
On the positive side.. you are VERY unlikely to be replaced in this company.. :D
21
u/Jygglewag Mar 15 '26
brooooo
rip.
I'd start by copying the function into another file and breaking it down into smaller ones. if you feel too lazy for it ask your favorite LLM to do it for you. They're usually not too bad at breaking down big functions.
5
u/HateBoredom Mar 15 '26
Please tell me thereβs a misplaced closing braces somewhere π
9
u/Substantial-Gain-596 Mar 15 '26
JavaScript be like that. There's a whole ass philosophy in that function
3
u/dashingThroughSnow12 Mar 15 '26
I stopped used Brackets because one file was too big for it.
3
u/Sea-Fishing4699 Mar 15 '26
this is the moment you realized why you still have a job
3
u/PhoenixInvertigo Mar 15 '26
Jesus christ
3
u/39AE86 Mar 15 '26
2
u/Gigibesi Mar 15 '26
i think i had a stroke
2
u/Kratoshie Mar 15 '26
ctrl c + open chatgpt (gpt 4.1mini) + ctrl v + "refactor this ples"
2
u/MrPringles9 Mar 15 '26
"I want this to be done by Monday!"
2
u/[deleted] Mar 15 '26
I get that this can sometimes be helpful and tbh I don't know that language but that function starts off defining a bunch of types and helper functions so maybe start by externalizing those?
2
u/mpanase Mar 15 '26
private function xD
who needs testing 13k loc?
2
u/Correct-Junket-1346 Mar 15 '26
Behold, my god FUNCTION
2
u/philtrondaboss Mar 15 '26
Install a Dead Code Detector extension. See if there's anything you can safely remove.
2
u/JadedFactor8776 Mar 16 '26
what the FUCK!?
2
u/playcalmed Mar 18 '26
Surely made with AI slop.
1
u/Hey-buuuddy Mar 15 '26
Use the Claude VSCode extension.
1
u/itzNukeey Mar 15 '26
what language is this?
1
u/awesomeplenty Mar 15 '26
So there are other longer functions??? How this file even get cloned bro
1
u/marquoth_ Mar 15 '26
"What does it do?" "Yes"
1
u/poorambani Mar 15 '26
If you have claide ypu can use /simplify skill and see if it helps you.
1
u/vitaliy_os Mar 15 '26
run!
1
u/Extra_Programmer788 Mar 15 '26
Delete everything and blame it on AI!
1
u/original_manatee Mar 15 '26
Hit the combination of verbosity and misery not seen since Tolstoy passed
1
u/lamalasx Mar 15 '26
I have once tried to refactor a 60k function which was generated by simulink. When compiling that C file the compiler just gave a warning that all optimizations are disabled due to how large that function was. I split it to like 20 smaller functions so the compiler optimizations start working. The funny thing is that after benchmarking, the 60k unoptimized version was faster...
1
u/Flimsy-Importance313 Mar 15 '26
Fun.
1
u/Personal_Cost4756 Mar 15 '26
Thatβs deeper than Reddit comments
1
u/Asleep-Bumblebee2167 Mar 15 '26
say you got a better idea
1
u/CubsThisYear Mar 15 '26
This is actually a much more solvable problem with AI. First thing I would do is have Claude write a shit ton of tests. Emphasize that the tests need to be small and self contained and tell Claude not to touch the existing code AT ALL.
Then when youβve reviewed the tests and they are all passing, just tell Claude to start refactoring. Itβs actually really good at this because even though the context is messy, itβs all there. Keeping 20K lines of code in context is not a big deal for an LLM even though itβs almost impossible for a human.
1
u/Frytura_ Mar 15 '26
Praise the lord and maybe the AI agent can help you
Wait is that untyped javascript?
1
u/BiasBurger Mar 15 '26
First make sure your test coverage of this function is 100% before touching it
1
u/MeLittleThing Mar 15 '26
pause the video and notice the nested functions.
1
u/MoneyTomato7711 Mar 15 '26
I love that cry emoji
1
u/SpaceToaster Mar 15 '26
I thought swift was supposed to be this masterful and performant back-end language. Turns out swifties are just a bunch of lazy vibe coders.
1
u/KrownX Mar 15 '26
It doesn't matter whether the company is a red flag or not. The real question is: IS THAT EVEN POSSIBLE???
1
u/MrCoffee_256 Mar 15 '26
Reminds me of the time I found eight identical methods where only one or two parameters in the method were differentβ¦
1
u/just4nothing Mar 15 '26
Been there, done that. Took me a whole summer to write the unit test, split the function bit by bit, confirm it worked as before, etc.
1
u/Lotus_Domino_Guy Mar 15 '26
It sounds like a fun refactor.
1
u/Simple-Olive895 Mar 15 '26
If it was python you could probably make it a one liner somehow.
1
u/DirkSwizzler Mar 15 '26
That's a target rich environment for refactoring.
1
u/intLeon Mar 15 '26
I once took over a project with 6k lines classes. Cant do more than partial classes unfortunately..
1
u/QuaaludeConnoisseur Mar 15 '26
Yknow i dont even know if i have written 13k lines of code in my life and these mf's put it in one function
1
u/Ckarles Mar 15 '26
The person who's gonna review your PR will put only one comment: "LGTM" then click on approve.
1
u/Felixfex Mar 15 '26
At least that function has an end, if you ever tried to debug code with 60 goto statements that lead to wildly different parts of other code, then you know you hit the peak of bad code
1
u/River-ban Mar 15 '26
Temple os (R.I.P)
1
u/sweetLew2 Mar 15 '26
Hey AI, write as many unit tests as possible to cover every branch and scenario in this function.
Hey AI, refactor this function to be less insane.
Tests still pass? Good to go.
1
u/Saajaadeen Mar 15 '26
fuck you there's no way thats a single function.
1
u/420-code-cat Mar 15 '26
JFC!!! What monstrosity is that? Wtf are you coding?
1
u/dbenc Mar 15 '26
I gasped out loud
1
u/Sotyka94 Mar 15 '26
I'm not reading all that shit. I will push it into the AI hell chatbot. If it survives, survives, if it not, it's not ment to be.
1
u/x-koded Mar 15 '26
Hello darkness my old friendβοΈ
1
u/Kiragalni Mar 15 '26
No matter who did it - that one knows nothing about real programming.
1
u/Old_Hotel1391 Mar 15 '26
they will probably fire you once you finish
1
u/Outrageous_Permit154 Mar 15 '26
No monolith on my repos
1
u/No_Cartographer_6577 Mar 15 '26
That was written by AI. There is no need for a function that long.
1
u/Usual-Analysis-2990 Mar 15 '26
Hilarious but honestly, it's probably not that bad. Guaranteed you can create a separate file with the parts that make it work and then break it into bits little by little.
1
u/jimmiebfulton Mar 15 '26
Call me a masochist, but I love refactoring shit shows. Very gratifying, like Origami or building wooden ships in a bottle kinda way.
1
u/Catharsis25 Mar 15 '26
That's what the clankers are for.
1
u/FlatWorldliness1061 Mar 16 '26
Looks like aosp code
1
u/goaty_mcgee Mar 16 '26
What even in the fuck?
1
u/MetroidvaniaListsGuy Mar 16 '26
Thats what my code looked like in university. Except that the function was the constructor of a java class.
1
u/_Vo1_ Mar 16 '26
Hey copilot, refactor this garbage.
cloudfare services down
1
u/1_H4t3_R3dd1t Mar 16 '26
yeah......
1
u/Independent_Ice_7543 Mar 16 '26
private func performApplicationFeatures
1
u/Tailslide1 Mar 16 '26
Did you get my old job?
1
u/jakeStacktrace Mar 16 '26
That's ridiculous. It doesn't even need refactoring, it's fine.
1
u/Relevant_Ad_8732 Mar 17 '26
Honestly sounds like a fun problem.Β
I'd probably start by diagramming exactly what the living fuck that thing does and go from there lol
1
u/Able_Act_1398 Mar 17 '26
Hey claude, suggest refactor od this monstrosity make no mistakes
1
u/ThePythagorasBirb Mar 17 '26
Legit might be better off untangling some ai slop atp
1
u/CsordasBalazs Mar 17 '26
1
u/Pure_Leopard8439 Mar 17 '26
Write unit tests for it
1
u/Ok-Bit-663 Mar 18 '26
Just keep extracting methods. Sometimes you have to merge them together or back to the original place when you have better understanding of that code. This is achievable.
1
u/armslice Mar 18 '26
Put it in its own module, export the function. Import the module. Change the any calls to reference the module. Run away.
1
u/Tzimitsce Mar 19 '26
I think the guy wrote his will; or constitution of the country he was born in among the function body or something as an Easter egg :)
Read it; maybe he will leave his fortune of 100 dollars to you if you tell him a password or something :)
1
u/thode Mar 19 '26
Just put it all into another function and say you "refactored" it all down to one line. Might work looking at the code they got.
1
u/AnythingEastern3964 Mar 19 '26
Thatβs going straight into an AI prompt. IDGAF about consequences or the result.
1
u/Existing_Pea_9065 Mar 19 '26
Dude call me crazy but I would love that. Like the idea of doing that makes me excited. I absolutely live refactoring old code. I've taken Cobol and rewrote it as C# before. It must be what it feels like for those people who take really old artwork and clean the years of grime off of it and fix it up nice.
1
u/Safe-Heat1644 Mar 19 '26
Damn bro, they let you refactor?!
1
u/maifee Mar 19 '26
AI can't replace this team. This many loc won't fit in its window.
1
u/Splatfan64 Mar 24 '26
I barely got into programming as a whole and this scares me immensely
1
u/sDenizOzturk Mar 24 '26
What about the function on line 144?
1
u/r1cked Apr 16 '26
lmfao. sorry bro
1
u/tinifed May 22 '26
Aah my olden days. a legacy codebase with a single 40k VS crashing .CS file and a 35k sql containing xml, that I had to work with every tooling, autocomplete and code hint disabled (basically at that point visualstudio was a nicely themed notepad)
43
u/[deleted] Mar 15 '26 edited Mar 15 '26
[removed] β view removed comment
22
u/[deleted] Mar 15 '26
[removed] β view removed comment
4
u/[deleted] Mar 15 '26
[removed] β view removed comment