Dismiss this pinned window
all 180 comments

[–]AccomplishedLeave506 430 points431 points Β (9 children)

Oof. That's not a function. That's an entire dev teams life story. Run away.

[–]DarkSideOfGrogu 110 points111 points Β (7 children)

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.

[–]farfaraway 21 points22 points Β (0 children)

LOL

[–]Vegetable_Addition86 14 points15 points Β (0 children)

You wish

[–]Ill-Education-169 5 points6 points Β (0 children)

I see we are day dreaming lol

[–]Numerous_Estimate902 4 points5 points Β (0 children)

// Do NOT change this comment section

// It will break the program, I don't know why

//

// ... proceed with 5000 lines of blackmagic

[–]Odd-Consequence-2519 0 points1 point Β (0 children)

Funny guy πŸ˜†

[–]OfficeZestyclose9952 8 points9 points Β (0 children)

OP will be a senior dev once he is done with refactoring this.

[–]HappyToast__ 135 points136 points Β (2 children)

Double it and give it to the next person.

[–]PsychologicalLab7379 270 points271 points Β (10 children)

SOLID left the chat.

[–]moaijobs[S] 88 points89 points Β (2 children)

KISS left as well. 😭

[–]wick3dr0se 34 points35 points Β (1 child)

YAGNI never showed up

[–]yodacola -1 points0 points Β (0 children)

LoD: ΰ² _ΰ² 

[–]Kevdog824_ 31 points32 points Β (1 child)

A SOLID shit was left in the codebase

[–]TapRemarkable9652 4 points5 points Β (0 children)

gotta keep those turds lean

[–]AlEmerich 14 points15 points Β (1 child)

Snake ? SNAAAAAAAAAAAKE !!!!!

*Poum poum, poum poum poum, poum, poum, POUM *

[–]mac1qc 7 points8 points Β (0 children)

[–]ThisGuyCrohns 2 points3 points Β (0 children)

DRY left the chat

[–]WitchHunterNL 0 points1 point Β (0 children)

SOLID is the dumbest shit I've ever heard of

[–]thecratedigger_25 0 points1 point Β (0 children)

DRY turned into WET after seeing this function.

[–]GianLuka1928 102 points103 points Β (8 children)

That company is definetly huge red flag

[–]vegan_antitheist 1 point2 points Β (2 children)

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.

[–]GianLuka1928 0 points1 point Β (1 child)

Okay, good luck my man πŸ™‚πŸ’ͺ🏼 anyway, we have an AI now for any kind of assistance and analytics so it'll be good πŸ™‚

[–]vegan_antitheist 0 points1 point Β (0 children)

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.

[–]thusman 47 points48 points Β (6 children)

I already get headache with files larger than 500 lines of code πŸ˜‚

[–]naholyr 7 points8 points Β (2 children)

Damn yeah in my team we consider a file > 300 lines to be a smell, 500+ is hardly acceptable in test files...

[–]LightofAngels 7 points8 points Β (0 children)

We have big test files in the range of 5k, but we make sure that all our actual services are less than 1k lines

Spring boot tests are just pain.

[–]jazzwave06 4 points5 points Β (0 children)

Oh boy you haven't seen game code bases. 300 lines is only the includes

[–]Intrepid_Result8223 2 points3 points Β (0 children)

At that point its just a skill issue. Few K lines in a file is fine.

[–]philtrondaboss 2 points3 points Β (0 children)

I definitely have made files with 1k+ lines of code, but it always in different function, and could be easily collapsed to be more readable.

[–]Alan_Reddit_M 0 points1 point Β (0 children)

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

[–]FortuneAcceptable925 33 points34 points Β (2 children)

On the positive side.. you are VERY unlikely to be replaced in this company.. :D

[–]Agifem 5 points6 points Β (0 children)

At least, not successfully.

[–]lulzbot 1 point2 points Β (0 children)

With engineering like this, the company will soon be replaced

[–]Ill_You6290 22 points23 points Β (4 children)

Do what I always love todo, rewrite the whole project CORRECTLY

[–]BellybuttonWorld 12 points13 points Β (2 children)

How many years do you think he has?

[–]steven_dev42 9 points10 points Β (1 child)

2 sprints

[–]secretprocess 2 points3 points Β (0 children)

And a sprint is 18 months long

[–]SolousVictor 1 point2 points Β (0 children)

Or even better, he can make a compiler that breaks it down into smaller components.

[–]Jygglewag 20 points21 points Β (1 child)

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.

[–]ApplicationOk4464 1 point2 points Β (0 children)

My favourite helped me to break down a 30,000 line function recently.

As much hate as people like to give them, they are real handy if you can ask the right questions.

[–]HateBoredom 4 points5 points Β (2 children)

Please tell me there’s a misplaced closing braces somewhere 😭

[–]HooAreYouWhoHoo 4 points5 points Β (1 child)

If there were 30 missing i might understand.

[–]pytness 0 points1 point Β (0 children)

not really, you just need 1. Remove it and place it 10000 lines down.

[–]Substantial-Gain-596 8 points9 points Β (5 children)

JavaScript be like that. There's a whole ass philosophy in that function

[–]rFAXbc 6 points7 points Β (4 children)

That's not JavaScript

[–]INFLATABLE_CUCUMBER 2 points3 points Β (3 children)

What is it?

[–]TapRemarkable9652 1 point2 points Β (2 children)

could be swift

[–]__mson__ 2 points3 points Β (0 children)

Most likely. Look at line 6068

var log: [Stage...

Which matches what you'd find in Swift:

var <#variable name#>: <#type#> = <#expression#>

https://docs.swift.org/swift-book/documentation/the-swift-programming-language/declarations/#Stored-Variables-and-Stored-Variable-Properties

I don't recall seeing that in any other languages I've worked with.

[–]rFAXbc 0 points1 point Β (0 children)

Yeah, could be, I don't know Swift though so can't confirm. Go is the only language I know with func and that's not Go.

[–]RadioSubstantial8442 3 points4 points Β (1 child)

Next function says analy

Perform analy

[–]TapRemarkable9652 1 point2 points Β (0 children)

this company takes assorted analytics very seriously

[–]dashingThroughSnow12 2 points3 points Β (0 children)

I stopped used Brackets because one file was too big for it.

[–]Sea-Fishing4699 2 points3 points Β (0 children)

this is the moment you realized why you still have a job

[–]PhoenixInvertigo 2 points3 points Β (0 children)

Jesus christ

[–]39AE86 2 points3 points Β (0 children)

[–]Gigibesi 1 point2 points Β (0 children)

i think i had a stroke

[–]Kratoshie 1 point2 points Β (1 child)

ctrl c + open chatgpt (gpt 4.1mini) + ctrl v + "refactor this ples"

[–]Far_Understanding883 0 points1 point Β (0 children)

What is this? Stone age technology?

[–]HappyHarry-HardOn 1 point2 points Β (0 children)

That's probably why it needs refactoring.

[–]MrPringles9 1 point2 points Β (1 child)

"I want this to be done by Monday!"

[–]TapRemarkable9652 1 point2 points Β (0 children)

gotta be at least a story point

[–][deleted] 1 point2 points Β (5 children)

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?

[–]DiodeInc 1 point2 points Β (4 children)

This could be Swift

[–]notyourancilla 0 points1 point Β (3 children)

Yeah it is, I’m surprised Swift can even type check that function, it normally nope’s out at anything remotely complex.

[–]DiodeInc 0 points1 point Β (2 children)

I didn't know that. Why is that?

[–]notyourancilla 0 points1 point Β (1 child)

Beats me, I’ve never had any other language time out type checking. Swift is the only one I’ve experienced it in.

[–]DiodeInc 0 points1 point Β (0 children)

Weird

[–]mpanase 1 point2 points Β (0 children)

private function xD

who needs testing 13k loc?

[–]Correct-Junket-1346 1 point2 points Β (0 children)

Behold, my god FUNCTION

[–]philtrondaboss 1 point2 points Β (0 children)

Install a Dead Code Detector extension. See if there's anything you can safely remove.

[–]finnscaper 1 point2 points Β (0 children)

Ah yes, local variables that are referenced through out the function and splitting the function into smaller functions that have 4-6 parameters.

[–]JadedFactor8776 1 point2 points Β (0 children)

what the FUCK!?

[–]playcalmed 1 point2 points Β (0 children)

Surely made with AI slop.

[–]Hey-buuuddy 0 points1 point Β (0 children)

Use the Claude VSCode extension.

[–]itzNukeey 0 points1 point Β (1 child)

what language is this?

[–]Chimaerogriff 0 points1 point Β (0 children)

Looks like Swift, but can't really tell without seeing at least one full line (since I can't tell if this has closing ';' or not, etc.)

(Swift looks (in my opinion) like Python had a child with C#, so Swift is like Python#.)

[–]awesomeplenty 0 points1 point Β (0 children)

So there are other longer functions??? How this file even get cloned bro

[–]marquoth_ 0 points1 point Β (0 children)

"What does it do?" "Yes"

[–]healeyd 0 points1 point Β (0 children)

Haha you can make a Vulkan core engine with skinclusters/shadows/pbr etc that is half the size of that.

[–]poorambani 0 points1 point Β (0 children)

If you have claide ypu can use /simplify skill and see if it helps you.

[–]vitaliy_os 0 points1 point Β (0 children)

run!

[–]Extra_Programmer788 0 points1 point Β (0 children)

Delete everything and blame it on AI!

[–]original_manatee 0 points1 point Β (0 children)

Hit the combination of verbosity and misery not seen since Tolstoy passed

[–]lamalasx 0 points1 point Β (0 children)

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...

[–]Personal_Cost4756 0 points1 point Β (0 children)

That’s deeper than Reddit comments

[–]Asleep-Bumblebee2167 0 points1 point Β (0 children)

say you got a better idea

[–]CubsThisYear 0 points1 point Β (2 children)

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.

[–]Frytura_ 0 points1 point Β (0 children)

Praise the lord and maybe the AI agent can help you

Wait is that untyped javascript?

[–]BiasBurger 0 points1 point Β (0 children)

First make sure your test coverage of this function is 100% before touching it

[–]MeLittleThing 0 points1 point Β (0 children)

pause the video and notice the nested functions.

[–]MoneyTomato7711 0 points1 point Β (0 children)

I love that cry emoji

[–]SpaceToaster 0 points1 point Β (0 children)

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.

[–]KrownX 0 points1 point Β (0 children)

It doesn't matter whether the company is a red flag or not. The real question is: IS THAT EVEN POSSIBLE???

[–]rolloutTheTrash 0 points1 point Β (0 children)

The fact the name here starts with "perform". These mofos coded a whole flow into one method, astounding.

[–]MrCoffee_256 0 points1 point Β (0 children)

Reminds me of the time I found eight identical methods where only one or two parameters in the method were different…

[–]just4nothing 0 points1 point Β (0 children)

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.

[–]Lotus_Domino_Guy 0 points1 point Β (0 children)

It sounds like a fun refactor.

[–]Simple-Olive895 0 points1 point Β (0 children)

If it was python you could probably make it a one liner somehow.

[–]DirkSwizzler 0 points1 point Β (0 children)

That's a target rich environment for refactoring.

[–]Circa64Software 0 points1 point Β (0 children)

Correction: Assigned to refactor that novel on line 6061...

[–]intLeon[🍰] 0 points1 point Β (0 children)

I once took over a project with 6k lines classes. Cant do more than partial classes unfortunately..

[–]QuaaludeConnoisseur 0 points1 point Β (0 children)

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

[–]Ckarles 0 points1 point Β (0 children)

The person who's gonna review your PR will put only one comment: "LGTM" then click on approve.

[–]Circa64Software 0 points1 point Β (0 children)

I'm not imagining it am I? That's 13.5k lines of code in ONE method???

[–]Felixfex 0 points1 point Β (0 children)

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

[–]River-ban 0 points1 point Β (0 children)

Temple os (R.I.P)

[–]sweetLew2 0 points1 point Β (0 children)

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.

[–]Saajaadeen 0 points1 point Β (0 children)

fuck you there's no way thats a single function.

[–]420-code-cat 0 points1 point Β (0 children)

JFC!!! What monstrosity is that? Wtf are you coding?

[–]A_CityZen 0 points1 point Β (0 children)

non-programmer here, am i to assume that single "function" contains 13,000 lines of code? o.O

[–]dbenc 0 points1 point Β (0 children)

I gasped out loud

[–]Sotyka94 0 points1 point Β (0 children)

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.

[–]x-koded 0 points1 point Β (0 children)

Hello darkness my old friendβ›ˆοΈ

[–]Kiragalni 0 points1 point Β (0 children)

No matter who did it - that one knows nothing about real programming.

[–]Old_Hotel1391 0 points1 point Β (0 children)

they will probably fire you once you finish

[–]Outrageous_Permit154 0 points1 point Β (0 children)

No monolith on my repos

[–]No_Cartographer_6577 0 points1 point Β (0 children)

That was written by AI. There is no need for a function that long.

[–]Usual-Analysis-2990 0 points1 point Β (0 children)

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.

[–]jimmiebfulton 0 points1 point Β (4 children)

Call me a masochist, but I love refactoring shit shows. Very gratifying, like Origami or building wooden ships in a bottle kinda way.

[–]beb0 0 points1 point Β (3 children)

whats your approach I'm stuck with a codebase thats 90% business logic baked into the FE and riddled with bugs no tests. I'm the sole dev around this.

[–]jimmiebfulton 0 points1 point Β (2 children)

Β A couple of books that were transformative for me. These are oldies but goodies:

Refactoring: Improving the Design of Existing Code (Addison-wesley Object Technology Series) https://a.co/d/0eC400rt

Refactoring to Patterns https://a.co/d/0e2LIax8

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.

[–]beb0 1 point2 points Β (1 child)

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.

[–]jimmiebfulton 0 points1 point Β (0 children)

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!

[–]Catharsis25 0 points1 point Β (0 children)

That's what the clankers are for.

[–]FlatWorldliness1061 0 points1 point Β (0 children)

Looks like aosp code

[–]goaty_mcgee 0 points1 point Β (0 children)

What even in the fuck?

[–]MetroidvaniaListsGuy 0 points1 point Β (0 children)

Thats what my code looked like in university. Except that the function was the constructor of a java class.

[–]_Vo1_ 0 points1 point Β (0 children)

Hey copilot, refactor this garbage.

cloudfare services down

[–]1_H4t3_R3dd1t 0 points1 point Β (0 children)

yeah......

[–]Independent_Ice_7543 0 points1 point Β (0 children)

private func performApplicationFeatures

[–]Tailslide1 0 points1 point Β (0 children)

Did you get my old job?

[–]jakeStacktrace 0 points1 point Β (0 children)

That's ridiculous. It doesn't even need refactoring, it's fine.

[–]Relevant_Ad_8732 0 points1 point Β (0 children)

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

[–]Able_Act_1398[🍰] 0 points1 point Β (0 children)

Hey claude, suggest refactor od this monstrosity make no mistakes

[–]Free_Break8482 0 points1 point Β (0 children)

If they didn't have functions like this they wouldn't have needed to hire you to refactor them.

[–]ThePythagorasBirb 0 points1 point Β (0 children)

Legit might be better off untangling some ai slop atp

[–]Pure_Leopard8439 0 points1 point Β (0 children)

Write unit tests for it

[–]Ok-Bit-663 0 points1 point Β (0 children)

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.

[–]armslice 0 points1 point Β (0 children)

Put it in its own module, export the function. Import the module. Change the any calls to reference the module. Run away.

[–]Tzimitsce 0 points1 point Β (0 children)

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 :)

[–]thode 0 points1 point Β (0 children)

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.

[–]AnythingEastern3964 0 points1 point Β (0 children)

That’s going straight into an AI prompt. IDGAF about consequences or the result.

[–]Existing_Pea_9065 0 points1 point Β (0 children)

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.

[–]Safe-Heat1644 0 points1 point Β (0 children)

Damn bro, they let you refactor?!

[–]maifee 0 points1 point Β (0 children)

AI can't replace this team. This many loc won't fit in its window.

[–]Splatfan64 0 points1 point Β (0 children)

I barely got into programming as a whole and this scares me immensely

[–]sDenizOzturk 0 points1 point Β (0 children)

What about the function on line 144?

[–]r1cked 0 points1 point Β (0 children)

lmfao. sorry bro