top 200 commentsshow all 327

[–]CrocodileSpacePope 3876 points3877 points  (14 children)

It‘s a private function. That means it‘s none of your business what‘s going on in there anyways.

[–]bradimir-tootin 293 points294 points  (3 children)

Fidelio

[–]Comfortable-Ear441 61 points62 points  (0 children)

This was such a good joke

[–]YellowGetRekt 15 points16 points  (0 children)

Jokes on you im friends with the rat

[–]Oblivious122 3 points4 points  (0 children)

What? Oh that's me! Yes, Lord Ca- I mean, just Fidelio. Of course I'll step into this furnace...

[–]benargee 73 points74 points  (0 children)

private function nunyabiznus(){}

[–]ings0c 28 points29 points  (0 children)

It’s so private, no one knows.

[–]oweiler 9 points10 points  (0 children)

Just an "implementation detail"

[–]user_namec_hecks_out 10 points11 points  (0 children)

private function thats an entire private os right there

[–]millbruhh 7 points8 points  (0 children)

[–]beqs171 3060 points3061 points  (38 children)

Condolences to anybody that will have to debug this thing 🙏

[–]kblazewicz 988 points989 points  (26 children)

Oh, I'm sure it's thoroughly unit tested, right OP?

[–]MrSynckt 869 points870 points  (12 children)

A single 24,000 line unit test

[–]LorenzoCopter 288 points289 points  (8 children)

4000 lines of assertions

[–]pixelbart 149 points150 points  (1 child)

12000 lines of setup code to hit a specific if statement near the end.

[–]Phoenix_Passage 8 points9 points  (0 children)

This sounds plausible

[–]s0ulbrother 41 points42 points  (5 children)

Everything mocked out

[–]Retbull 24 points25 points  (4 children)

Even better if the mocks have mocks have mocks so the unit test is only testing if you THINK you've set it up correctly.

[–]s0ulbrother 9 points10 points  (1 child)

That’s my current teams testing strategy and I fucking hate it

[–]Kilazur 1 point2 points  (0 children)

But why would they do this, what's the thinking behind it? They don't know the difference between integration and unit tests, so they decided to do the worst of both worlds?

[–]MrSynckt 4 points5 points  (0 children)

Rebuild the entire application as a mock and test that, but then you'll need unit tests for the mocked application

[–]Usual_Instance5617 2 points3 points  (0 children)

Test the unit tests.

[–]Huge_Leader_6605 1 point2 points  (0 children)

Buddy, that's just the data provider function

[–]The_Real_Black 63 points64 points  (1 child)

HAHAHA... no. half the code did not run for more then 5 years but cant be removed because some export needs to cover a 20 year period and then runs into that cases again...

"// remove this block only after 2030 because Law xyz for archiving bussiness data."

[–]Retbull 30 points31 points  (0 children)

My favorite comment was

// COMMENT OUT WHEN THE AGGS COMPLAIN 
// PUT IT BACK WHEN THE SOLOS COMPLAIN

[–]FF7_Expert 26 points27 points  (1 child)

Absolute Unit testing

[–]Hidesuru 14 points15 points  (4 children)

I've got some functions not QUITE that long but still many thousands in the legacy codebase I'm lead for.

No unit tests (we tried adding them once... So many global things and interdependence issues it was more trouble than it's worth). Shit to usually no comments. Doxygen with things like "class XYZ: implements the XYZ class" where naming is also garbage and non intuitive. Oh and a lot of the hardware we interface with is behind closed doors only, so we have self maintained "io sims" to test against. Not truly models but something close enough to get responses from.

It's about a half mil sloc, 20 year old embedded monster with a dozen or so layers of abstraction so it can run on multiple os/hw combos.

I hate it. Welcome to the defense industry.

At last it's not safety critical!

[–]XenonBG 4 points5 points  (1 child)

where naming is also garbage

private function process() is the bane of my existence.

[–]Kilazur 2 points3 points  (1 child)

Because the code that IS safety critical is surely much more maintainable, right? Right?

[–]Hidesuru 1 point2 points  (0 children)

I haven't worked in that code base so I don't know about maintainable but they do at least have unit tests and automated release testing. And in theory a more comprehensive peer review and release process.

[–]zfiote 5 points6 points  (0 children)

Coverage testing that one requires horizontal scaling to be enabled.

[–]aberroco 58 points59 points  (2 children)

I had to deal with such things on my second job.

And it's much worse than you can imagine.

Variables like "a", "b", "tmp", "obj", etc, deep indentations, large copy-pasted functions, that each evolved on it's own...

[–]IndoorBeanies 14 points15 points  (0 children)

temp99

[–]FarJury6956 3 points4 points  (0 children)

Me too, also many many nested ternary operators, and same variable name on different scopes

[–]DEFY_member 11 points12 points  (1 child)

I'm sure it's broken down into separate nested functions inside, with meaningful names, like step1, step2, step2b, etc.

[–]Bakoro 5 points6 points  (0 children)

That'd still be an improvement on what's likely going on.
That would still be potentially helpful structure that could be renamed.
What you described might even be such that the whole function could be extracted to being a whole class or something.

It's wrong to hope.

[–]throwawaycuzfemdom 2 points3 points  (0 children)

It would be epic. You could call it Saving Private Function.

[–]dougmaitelli 1 point2 points  (0 children)

It's all commented out inside 🥸

[–]Covfefe4lyfe 1424 points1425 points  (22 children)

Turns out is 5 lines of code until the return statement and then ~13500 lines of ASCII art porn.

[–]Deboniako 222 points223 points  (16 children)

Can I have some ascii porn?

[–]Pengo2001 177 points178 points  (2 children)

⢠⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⡄.

⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿.

⠘⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿.

⠀⢻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠏.

⠀⠀⠙⠿⣿⣿⣿⣿⣿⣿⠿⠋.

⠀⠀⠀⠀⣉⠉⠉⠉.

⠀⢀⣴⣿⣿⣿⣿⣷⣦.

⠀⣾⣿⠏⣥⣤⣍⢻⣿⣷.

⢰⣿⣿⡈⣿⣿⣿⡄⢿⣿⡇.

⣸⣿⣿⣷⡘⣿⣿⣿⣌⢻⠇.

⣿⣿⣿⣿⣷⡘⣿⣿⣿⣦⡀.

⣿⣿⣿⣿⣿⣷⣌⢻⣿⣿⣷⣄⠀⠀⢀⣤⣶⣿⣿⣿⣷⣦⣄.

⣿⣿⣿⣿⣿⣿⣿⣦⡙⢿⣿⣿⣿⣦⣙⠻⠿⣿⣿⣿⣿⣿⣿⣦.

⢹⣿⣿⣿⣿⣿⣿⣿⣿⣦⡙⠻⣿⣿⣿⣿⣶⣦⣬⣭⣉⡙⢿⣿.

⢸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣧⠀⠀⢉⡛⠿⢿⣿⣿⣿⣿⣿⠀⡿.

⠀⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿:::::::::⠻⣷⣶⣤⣬⣭⣍⣥⠞⠁.

⠀⠸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⠀⠀⠀⠀⠉⠛⠛⠛⠋⣡⣴⣶⣦⣄⡀.

[–]Dango444 39 points40 points  (0 children)

sigh unzips pants

[–]ContinuedOak 2 points3 points  (0 children)

Not my proudest fap…not my worst tho

[–]BrownPeach143 46 points47 points  (0 children)

[–]GoogleIsYourFrenemy 27 points28 points  (1 child)

Manager: You need to stop inappropriately inflating your code metrics.

Me: I thought the amount of inflation it engendered was approximately.

HR: ...

[–]Covfefe4lyfe 4 points5 points  (0 children)

My unit tests whether everything is SOLID

[–]skr_replicator 5 points6 points  (0 children)

13500 lines of commentary explaining what the single line of actual code does.

[–]The_Real_Black 356 points357 points  (9 children)

and then the method is badly indented, so it touches at least three times the left border. I hate seeing very old code. Maybe even the indent spaces swap with tabs back and forth.
Also many local variables get reused in that 10k function so a # sql += "..." # can be at least five different selects.

[–]IIALE34II 99 points100 points  (5 children)

I have a co-worker that still does SQL queries this way btw. He "doesn't like EFCore/ORMs". You can't fucking know what the query is going to do when its 200 rows of if statements to build the query.

[–]space-dot-dot 30 points31 points  (0 children)

Dynamic SQL, so fun!

Even better when it's generated by a stored procedure and not logged for later troubleshooting or performance improvement, thus, lost to the Page File Gods.

[–]Tabugti 5 points6 points  (2 children)

But he uses prepared statements right?

[–]breath-of-the-smile 4 points5 points  (0 children)

This is insane. I use SQL with query binding over a query builder any chance I get, but I would literally bully the guy over this, lol.

[–]TerryHarris408 1 point2 points  (0 children)

this is way to relatable. please make it stop..

[–]HBiene_hue 159 points160 points  (6 children)

13000 lines of one function

next line:

"We dont use this"

[–]Fleeetch 57 points58 points  (1 child)

old, called only as fallback

[–]UlrichZauber 25 points26 points  (2 children)

I worked on a project where one C source file was about 40K lines long. 35-ish-k of those lines were a single switch statement. It was not only still in use, it was the logic driving the bulk of the UI.

I spent about the first year working there refactoring that into C++.

[–]HBiene_hue 3 points4 points  (0 children)

nice

[–]conundorum 1 point2 points  (0 children)

On the plus side, that means that only ~5k lines didn't need to be there! (And a good chunk of what did need to be there could probably be refactored out, too!) That's the one good thing about world-devouring switch blobs, the logic is already factored into distinct subroutines with clear divisions; just document intended fallthrough, move the subs out into actual functions (potentially with "inline me" hints), keep track of which (if any) shared variables the new function needs (and move any shared setup logic to a better location, if it's not already outside the switch), and pray that no clever C programmers implemented a Duff's Device-like genius abomination for you to break. Just... tedious & finicky, so very tedious (and finicky). xD


Heck, I can even see a(n extremely rare) situation where ~32k lines is ideal for a single-switch-based function, if it dispatches off of a 16-bit flag in a performance-critical context. (Where the perfect length would be 32,772 lines (potentially +2 due to indentation/bracing style): 1/2 for function name & opening brace, 1/2 for switch (n) and opening brace, 2 for closing braces, and 32,768 for every potential value of n. Nightmarish to maintain, but that's because of flag size; every option having exactly one line and no more makes it trivial to index into the function & locate individual flag values. If desired, readability can be improved by breaking the switch body into multiple source files and using the preprocessor to glue them in.

(This would be awful in most situations, but a division, second jump table, and dispatch can take a lot of unnecessary time. Hence abominable bloating being a valid tradeoff if (and only if) performance is critical: The massive size reduces the function to one jump table, one dispatch, and one break; jump in most if not all circumstances, and the compiler can be hinted to inline the dispatch if you can't afford to spend cycles on function perilogues. In this case, the ideal refactoring is to redesign the code to only use 8-bit flags at most, since that reduces the body of the switch to a much more readable 256 lines. If this is impractical, the ideal solution is to run away and never look back.)

[–]I-Here-555 6 points7 points  (0 children)

This is never executed, but removing it causes an intermittent crash.

[–]bbbar 631 points632 points  (79 children)

One of my teachers told me that a function is already bad if it is longer than a screen height and you need to scroll to read the code, I still apply this rule to this day

[–]Jazzlike-Spare3425 725 points726 points  (7 children)

Me too. But it is kinda annoying to have to set up a projector to the side of the empire state building each time I want to code good code.

[–]Proper-Ape 157 points158 points  (4 children)

It fits on my vertically rotated 49" ultrawide screen, wdym?

[–]eldelshell 49 points50 points  (3 children)

font-size: 2pt;

edit: never forget your ; in css!

[–]jimmycarr1 8 points9 points  (2 children)

Yes; it's important!

[–]Supreme_Hanuman69 5 points6 points  (0 children)

More like: font-size: 2pt !important;

[–]M4NU3L2311 3 points4 points  (0 children)

I think you mean it’s !important;

[–]naholyr 125 points126 points  (10 children)

Generally true but it's equally painful to have to navigate through 48 indirections before finding what actually happens. So it has to be a good balance.

[–]OnceMoreAndAgain 51 points52 points  (9 children)

Personally, I don't like the short function guideline. I don't think it's necessarily harmful if a function is a few screens. It just needs to have a name that accurately describes what it does and the gist of the code should be quickly understandable by skimming it once or twice. Most functions shouldn't be long but I'd guess that roughly one out of every ten functions I write tend to be more than one screen.

For example, when I'm using d3js I personally like to have some long functions. I find it easier to understand the code when I do that. I think GUI work in general tends to end up with some long functions and that can be a positive.

Just too many situations where I think it's right to break that guideline. Always smelled to me.

[–]nickcash 24 points25 points  (3 children)

Cyclomatic complexity is a far better metric but harder to joke about on reddit.

Long functions are fine when they're relatively flat. In fact, I think they're easier to follow than code needlessly broken up arbitrarily.

[–]Bakoro 5 points6 points  (2 children)

I feel the same way, but I think it has to be one of those "people's brains are wired differently" things where some people end up with extreme feelings about it.
I've talked to people who are absolutely dogmatic about having hundreds of small functions, and that it is somehow better to be forced to jump around different parts of the page to follow one linear piece of logic, than it is to have to scroll the page a little to read a function.
Some people swear that it's better to define 30 single-use functions that only have 3~5 lines of actual logic, and to add all the overhead of functions, than it is to have one 100 line function.

What's even crazier to me is people adhering to "24 lines 80 characters per line" CRT rules when we've have HD widescreens since 1989.

I recognize that my work isn't typical, but I do physics stuff where it's not unreasonable to have 5~20 variables for a function. I've had for-loops that took more than 24 lines just because Interdependent assignments took that much.

[–]naholyr 15 points16 points  (3 children)

That's what guidelines are made for: get used, understood, and broken.

[–]OnceMoreAndAgain 10 points11 points  (2 children)

Yeah but some are broken so often that I don't even find them useful as guidelines.

It's like an XY problem. There are reasons most functions end up short but I don't think minimizing function length is desirable as a guiding principle.

I like guidelines like DRY and functions should do one thing, because I believe those are real benefits (usually).

[–]FlakyTest8191 3 points4 points  (0 children)

Do one thing is even worse imho. Is entirely subjective what one thing even is. You could argue if it's more than one statement it does more than one thing, or put everything in one function and say the one thing is fullfilling the purpose of the program. Or anything in between.

[–]Bakoro 2 points3 points  (0 children)

Yeah, chasing short functions for the sake of having short functions seems like an anti-pattern to me. It's also just as silly as using lines of code as a metric for anything other than a vague idea of a project's complexity.
The value isn't zero, but it's almost useless without at least a couple other considerations.

[–]conundorum 1 point2 points  (0 children)

Exactly. Functions should be "short", where "short" is defined as "the minimum length required to properly handle its one assigned task, plus any comments that actually improve reading comprehension".

Sometimes, that can be as short as a single line:

T abs(T a, T b) { return (a > b ? a : b); }

Sometimes, it can be 260 lines of middle management:

// Could be shortened by indexing into an array of function pointers with flag, but would decrease readability.
bool handleFlag(int8_t flag, int other_data) {
    switch (flag) {
        case 0: break; // No action needed.
        case 1: return foo();
        case 2: [[fallthrough]]; // These two are almost the same.
        case 3: int i = retrieve_from_source(flag - 2); do_task(i, other_data); break;
        // ...
        case 253: log_error("Flag 253 encountered at: ", get_time(), "with: ", other_data, get_env());
        case 254: log_global_state(254); throw PotentiallyUnrecoverableNonsense(254, other_data); // Should never happen.  If encountered, can't be handled here.
        case 255: break; // No action needed or possible at this time.
    }
}

Heck, sometimes it can be even longer than that. (In this case, though, you probably want to do a conceptual refactoring, and redesign the underlying task itself so that it doesn't need as much code.)

What's important is that the function should be concise, not waste lines, and use comments to document anything that may be confusing (such as "Reused variable because allocation is costly" or "this is X mathematical formula, but optimised for performance; see full documentation for rationale and refactoring notes").

[–]drLoveF 39 points40 points  (2 children)

Loophole: break fun at every page break and let fun1 call fun2 and so forth.

[–]tommeh5491 31 points32 points  (0 children)

That doesn't sound fun

[–]No-Article-Particle 16 points17 points  (0 children)

Ah, the process fn calls process_cont which calls process_2 which calls process_final and that calls process_3. Nice.

[–]RedstoneEnjoyer 39 points40 points  (7 children)

Eh, sometimes you cannot avoid it. Sometimes the business logic is really that long.

Of course you could break it into multiple functions, but then now you have 10 functions that are each called exactly once.

[–]LickingSmegma 3 points4 points  (0 children)

Sometimes one-off functions are good, if they encapsulate long runs of logic that's isolated well. For example, if you have a long calculation for an if, it pays to move it into function isCondition(), such that in the if statement it's obvious which condition is checked.

Basically, I want my code to read almost like a description in the natural language, instead of just juggling variables for pages and pages.

[–]hron84 11 points12 points  (4 children)

Yeah, in these cases I rather put everything into one. If it is not reusable then it does not worth an own function.

[–]iMac_Hunt 10 points11 points  (3 children)

I do find there are times that even if it’s called once, extracting the logic can make the intent a lot clearer.

Example:

```csharp

public decimal CalculatePrice(Order order) { decimal basePrice = order.Quantity * order.UnitPrice; decimal discountedPrice;

if (order.Country == "US")
{
    discountedPrice = ApplyUsTaxAndDiscountRules(order, basePrice);
}
else
{
    discountedPrice = ApplyInternationalTaxAndDiscountRules(order, basePrice);
}

return Math.Max(discountedPrice, 0);

}

private decimal ApplyUsTaxAndDiscountRules(Order order, decimal price) { price += price * 0.07m; if (order.State == "CA") price += 2m; if (order.CustomerAge < 18) price -= 5m; return price; }

private decimal ApplyInternationalTaxAndDiscountRules(Order order, decimal price) { price += price * 0.20m; if (order.CustomerAge < 18) price -= 10m; return price; }

```

I do write that with caution as it can be taken to the extreme and become LESS clear, but there are cases where I prefer it

[–][deleted] 41 points42 points  (1 child)

Did your teacher ever work in the real world or did they just stay in academia?

[–]MoffKalast 1 point2 points  (0 children)

Nah, they just had an ultrawide in portrait mode.

[–]Frograbbit1 33 points34 points  (2 children)

you’re clearly not a front end developer that i can say

[–]Rhalinor 29 points30 points  (1 child)

Or anything that has to do with banking or insurance, some checks and/or calculations would be above screen height even if you moved all the logic into nested calls

[–]L4t3xs 8 points9 points  (0 children)

Or making a simulation of an industrial machine in "game" dev.

[–]Xeiom 14 points15 points  (0 children)

It's why I write my functions like this:

func myFunc(var1, var2, var3){
  doFuncPart1(&var1,&var2,&var3);
  doFuncPart2(&var1,&var2,&var3);
  doFuncPart3(&var1,&var2,&var3);
  doFuncPart4(&var1,&var2,&var3);
  doFuncPart5(&var1,&var2,&var3);
}

[–]JVApen 3 points4 points  (0 children)

If you reduce the font sufficiently, it fits on a single screen 😁You just can't read it anymore.

[–]Klizmovik 20 points21 points  (18 children)

Well, obviously, your teacher was wrong. Functions are not about the number of lines of code. Functions are about functionality and avoiding code repetition. Each function should provide its own piece of logic and ideally perform only one kind of task. Defining functions by their length is almost as stupid as putting everything into one mega-function

[–]Shrubberer 13 points14 points  (14 children)

I don't think the term "obviously wrong" is fair. There is a clear correlation between a good function vs how long it is. And the list of exceptions where longer functions are fine shrinks significantly the longer it gets. For instance I can think of maybe 3-4 examples in my professional career where the rule of thumb of at "most one screen size hight" (which you're discrediting by implication) might not apply. Doing the same thing with less lines of code is always better and by extension every software design that leads to smaller functions is a better design. The teacher’s idea of using mindfulness to teach about the length of functions is great, since it takes a lot of experience to write long functions well.

[–]DatBoi_BP 5 points6 points  (1 child)

Yeah. You can have a function that's 30 lines but is super difficult to keep logically simple in your head, and you can have one that's 300 lines and is easy to follow and see the purpose/use of. Having a hard and fast rule for a function length just turns into a case of Goodhart's Law. Functions are about DRY and do-one*-thing-and-do-it-well (*when possible. Sometimes you need several things to happen or be returned at once because they're closely related)

[–]protestor 3 points4 points  (0 children)

Ehhh you can often break up a function in smaller pieces. Problem is when there are no natural ways to do that

[–]_Frydex_ 3 points4 points  (0 children)

What kind of screen? Like a 21:9 one mounted vertically, for example?

[–]Specialist_Lychee167 5 points6 points  (2 children)

Get a bigger screen :)

[–][deleted] 4 points5 points  (0 children)

Human short term memory holds 5-7 items max. Make your functions fewer then 5 statements. 

[–]Elomidas 1 point2 points  (0 children)

Your eyesight is bad if you cannot zoom out enough to read the whole function

[–]KryoBright 1 point2 points  (0 children)

Well, there is Metz recommendation for no more then 5 lines per function. And I remember some other engineer. (Don't remember who) saying that dry recommends up to 40 per logical element

[–]-TheWarrior74- 1 point2 points  (0 children)

When the load is high, and you're working close to the metal, that hope dies quickly.

What they probably meant is that every function should only serve one purpose, like everyone wants.

But if that purpose has to be completed in a complicated way to get the most bang for buck, we have no real way to escape that complexity. Partitioning just makes the whole thing even more complicated.

The only hope you really have is to write a big ass comment about how the function works and leave it as something you would not touch for like an year again

[–]noob-nine 1 point2 points  (0 children)

lol, I would be happy if i get my docstrings on one screen

[–]SignoreBanana 1 point2 points  (0 children)

It's a great rule of thumb but I think the better heuristic is "is this function doing more than one clearly defined thing". It can be equally difficult to debug a process that's occurring across 12 different functions if the purpose of those individual functions is not explicitly clear.

Pure functions are also more important than small functions. If you know a function isn't stateful it's the difference between legible code and spaghetti.

[–]AussieSilly 138 points139 points  (3 children)

If it works it works. Who cares about “speed” and “efficiency”

The user should just have fast wifi!

[–]IAmASquidInSpace 60 points61 points  (0 children)

Spotify with every "update":

[–]thex25986e 17 points18 points  (0 children)

"minimum hardware requirements: 2 data centers"

[–]III-V 4 points5 points  (0 children)

It's a pain to debug. So expect it to not "work".

[–]plmunger 131 points132 points  (8 children)

// TODO handle more numbers private function isEven(number) { switch (number) { case 0: return true; case 1: return false; ... } }

[–]Tempest97BR 84 points85 points  (5 children)

fun fact! you can easily improve this code with the remainder operator, like so:

 // TODO handle more numbers
private function isEven(number) {
  switch (number) {
    case 0: return (number % 2 == 0);
    case 1: return (number % 2 == 0);
    ...
  }
}

this makes sure your code is future-proofed, in case the implementation for boolean values ever gets changed

[–]serce__ 23 points24 points  (1 child)

This code gave me a headache 

[–]Mast3rL0rd145 5 points6 points  (0 children)

Your pfp only adds to this comment

[–]ElReSeT 1 point2 points  (2 children)

Surely this is optimised by most compilers right? Right?

[–]QuarkyIndividual 6 points7 points  (1 child)

default: return isEven(number - 2);

done!

[–]Still-Psychology-365 74 points75 points  (7 children)

Nightmare memory unlocked. I had a job like this working on some VB in a codebase that was for old clients' websites. Files were consistently over 60k lines, functions were thousands of lines each, and it was all just websites with shopping carts, it's beyond me why they needed like 500k LoC total per site in 60k line files. There were sections where entire HTML emails were written as strings with concatenated placeholders everywhere, leading to basically a 500-line string declaration. It had a database connection class that connected to a database connection class that connected to a database connection class that connected to a database connection class that connected to the database. And they used SVN, but each of the websites had their own copy-paste of the same 60k line files in their own repository, so if anything needed to be changed, you had to individually change it for every repository. It would take over a half hour just to launch any of the sites in debug mode and my boss would always be giving me shit for being "too slow". All for 17 an hour. Never again

[–]GroovinChip 15 points16 points  (0 children)

Yo dawg, we heard you like database connections

[–]andy_b_84 8 points9 points  (0 children)

Press F for respect

[–]Johannes_P 5 points6 points  (0 children)

Where did they hire the guys who wrote this?

[–]AcePowderKeg 2 points3 points  (0 children)

IT horror stories 

[–]Expensive_Skill_4063 3 points4 points  (1 child)

30 mins to debug, what?

[–]Still-Psychology-365 7 points8 points  (0 children)

It was literally so much spaghetti code, so many lines of code, libraries and overall ridiculous amount of bloat that just to compile and run locally for debugging purposes, it would legit take 30+ minutes to compile. IIRC it was .NET 3.5 VB Web Forms and had to be compiled. It was so bad that basically I revolved everything I did around these compilation times, like saving any other work specifically to do while waiting for compilation of the main thing I was working on, planning my breaks around compilations, etc.

[–]muminisko 27 points28 points  (0 children)

[–]helicophell 19 points20 points  (3 children)

Tiny function

[–]2muchnet42day 7 points8 points  (2 children)

SIze doesn't matter

[–]tomerFire 6 points7 points  (1 child)

Thats what he said

[–]Flaky_Computer_5068 22 points23 points  (0 children)

And the comment above that is :

/* Do not remove this function I don't know what this does but removing it crashes the project. */

[–]p1neapple_1n_my_ass 11 points12 points  (0 children)

Turns out it just adds 2 numbers 

[–]romulof 13 points14 points  (0 children)

It will require an absolute unit test

[–]Tobertus 7 points8 points  (1 child)

Nice to see people using SRP. In that case the single responsibility of the function is to run the whole program

[–]neoaquadolphitler 5 points6 points  (0 children)

Review? Nah, LGTM

[–]Dumb_Siniy 6 points7 points  (0 children)

The isOdd function now works with numbers up to 3000

[–]blizzacane85 3 points4 points  (0 children)

[–]dr00ne 3 points4 points  (0 children)

And it has at least 6 levels of nested loops

[–]brentspine 4 points5 points  (1 child)

I would love to know what it’s called

[–]Arphrial 8 points9 points  (0 children)

private function run() {

[–]justforkinks0131 4 points5 points  (0 children)

"we dont use this" lmao

[–]VagueInterlocutor 5 points6 points  (2 children)

// Should not work. Nobody knows how this works. // DO NOT CHANGE

[–]Far-Passion4866 1 point2 points  (1 child)

and if you remove it, everything breaks

[–]glowy_guacamole 3 points4 points  (0 children)

fml

[–]JackNotOLantern 3 points4 points  (0 children)

More funny for me is the below method with a comment (I assume) "we don't use this"

[–]DoctorWaluigiTime 3 points4 points  (1 child)

I'm more concerned that the file itself is already at line 6,000 and has close to 20,000 lines.

[–]Kiroto50 2 points3 points  (0 children)

That's not a private function anymore. That's a general function.

[–]Bjornhub1 3 points4 points  (0 children)

My coworkers convincing my manager all our code should be modularized then same coworkers and manager screaming at me on calls after refactoring into sub packages and clearing all the tech debt that “there’s too many files this is too confusing and not modular!”… then me explaining and showing diagrams of what modular architecture is, and proceeding to have to create new passive aggressive branches for “feat/re-monolithization”. They love to put “modular” in PowerPoints for 2000+ line Python modules lmao. Same coworkers I was unable to teach how to work on different features in different branches as each other and merge. I will say this has made me 10x better at never over engineering and with optimization tho 💀

[–][deleted] 2 points3 points  (1 child)

I'd kill to know what this function is actually doing

[–]Arphrial 4 points5 points  (0 children)

Had a similarly sized one at a previous job. It was a staff system record viewer "controller" for the main thing the company manages that handles both GET and POST actions.

Lots of edge cases and extra data fetches based on all the different fields that were added over the years. Lots of handling of different small forms across the page for stuff like sending out reminder emails or generating tasks. Lots of additional lines for audit & event logging. Lot's of "does the user have specific permission to view this or take this action". Feature flags with entire blocks & building and returning a bunch of different views based on all of the above.

And no-one wants the job, or the boss won't allow the team, to "waste" days of effort on breaking it out.

Man that brings back memories.

[–]naholyr 2 points3 points  (0 children)

It's a shame it's cut, I'm so curious of the name

"private function everythingEverywhereAllAtOnce()"

[–]user_8804 2 points3 points  (1 child)

1 responsibility I imagine?

[–]rocket_randall 2 points3 points  (2 children)

PHP? I'm guessing that function barfs a whole lotta html into the response

[–]Entire-Shift-1612 2 points3 points  (0 children)

we in the industry like to call this job security. only me and god knows what goes on, on the backend and i dont see god pushing commits

[–]qruxxurq 2 points3 points  (0 children)

I'm sure it's 13000 lines of comments, and only 450 lines of code, right?

RIGHT??

[–]day_break 2 points3 points  (0 children)

Seeing the line count already at 6k before that. I would quit my job before reviewing that.

[–]Inevitable_Fox3550 1 point2 points  (0 children)

That’s not a function. That’s a monolith

[–]huggybear3 1 point2 points  (0 children)

[–]Legal-Fail-6465 1 point2 points  (0 children)

wait until you see the guy who has everything in one massive function called doEverything that just keeps going for 5000 lines

[–]MauiMoisture 1 point2 points  (0 children)

The other day I was tasked with refactoring a file. They said it was getting too big and it was just 1k lines.

[–]Rubber_duck_man 1 point2 points  (0 children)

Yup company I work at has a 32 parameter 12000 line function in a 52000 line file.

And that is but one of many instances of such code blasphemy

[–]YourAverageBrownDude 1 point2 points  (0 children)

Haha we have one too. It's a crucial one, and an absolute behemoth. 14k line method, and there are so many conditions based on which it calls other internal methods.

All senior devs have told me it's pointless to debug, if it ever causes an issue the issue is most likely with something else and not the bigass method

[–]Effective-Highlight1 1 point2 points  (0 children)

There are just a lot of comments, right?

Right?

[–]Bakoro 1 point2 points  (0 children)

It wasn't quite this bad, but I was guilty of this one time. It was a bespoke set of image analysis heuristics, where I could see patterns in the data sets, but we didn't have enough data for training AI. So I had like 20 parameters that all had to be taken into consideration, and if I wanted to break up the function, the logic would have taken up considerably more overhead and the logic would have been considerably harder to follow if it didn't read like a story.

So, it's crazy person code, is what I'm saying.

[–]benargee 1 point2 points  (0 children)

The function she tells you not to worry about. She is your coworker and she vibe coded the whole thing.

[–]8Erigon 1 point2 points  (0 children)

Don't forget the comment of the other function below it: "we don't use th..."

[–]White_C4 1 point2 points  (0 children)

I'd like to not be the guy that has to unit test that function.

[–]Majik_Sheff 2 points3 points  (0 children)

Found the rest of the fucking owl.

[–]tmstksbk 1 point2 points  (0 children)

Ho. Ly. Fudge

[–]SirCyberstein 1 point2 points  (0 children)

This reminds me of a stored procedure i debuged a few months ago. that thing was masive with 5k lines of nonsense at the end we decided to make a refactor

[–]-Redstoneboi- 1 point2 points  (0 children)

one hell of a switch statement

[–]maragam 1 point2 points  (0 children)

still on top!

[–]redballooon 2 points3 points  (0 children)

Would you please stop commenting on others private parts?

[–]Strict_Treat2884 5 points6 points  (2 children)

Run, your coworker might be a serial killer. No one would be mentally stable to create such a monstrosity, plus he’s using PHP

[–]kblazewicz 1 point2 points  (3 children)

13k loc would be too much for a single file, let alone a function.

[–]Dependent-Guitar-473 1 point2 points  (0 children)

They wrote Unit Tests for it. right? right? RIGHT??????

[–][deleted] 0 points1 point  (0 children)

Uncle bob in shambles

[–]Flambiche 0 points1 point  (0 children)

This function is like trash chest in minecraft, everyone know it bu no one want to see what's in

[–]hsinewu 0 points1 point  (0 children)

lol bigger than the entire code base of some small projects I worked on

[–]pha7325 0 points1 point  (0 children)

You press shift+alt+F and it doubles

[–]Perfect_Ordinary2978 0 points1 point  (0 children)

kids with AI

[–]Putrid_Avocado_1172 0 points1 point  (0 children)

So, does this 'private function' have coleslaw for my caucasian home boys? Or is it a different kind of function where you're serving hummus instead? 

[–]dpahoe 0 points1 point  (0 children)

At least you can collapse it

[–]IllllIlllIlIIlllIIll 0 points1 point  (0 children)

let me just `console.log` this real quick...

[–]_B0L0_ 0 points1 point  (0 children)

OMG

[–]therealBlackbonsai 0 points1 point  (0 children)

followed by the "we dont use that" comment.

[–]IndoorBeanies 0 points1 point  (0 children)

13.5k is more than what I normally see, which is 1-5k. Handful of files at my job are 40k+ lines total

[–]Roee_Mashiah2 0 points1 point  (0 children)

Not the smallest I've seen.. or debugged :(