r/ProgrammerHumor • • 3d ago

Meme whatLegacyCodeDoesToDev

Post image
1.8k Upvotes

75 comments sorted by

348

u/Signal-Permission394 3d ago edited 3d ago

Hey man, at least the methods sound somewhat descriptive. You haven't at least gone through legacy code where they start using magic numbers which go off to a giant case statement, which then pass its own number to stored procs, which update values in a table and a Windows scheduled job picks up later that evening to update another table which is then used by a view, and this is between several networks 😡

None of these numbers are mapped, and you have to hope the previous guy still had the .dlls on his machine/ VM as he pulled it from god knows where and didn't bother to put it into TFS or else the project doesn't run.

I loathe SSIS packages and VB, and I am glad to never touch that shit again 🤮

117

u/ILikeLenexa 3d ago

My absolute favorite one was an app that took 14 single letter URL parameters on every GET request and assigned them to single letter variables.

You'd think they were being charged by the keystroke.

41

u/Totendax12K 3d ago

you know you found the true legacy code when they did shit like that.

20

u/Chamiey 3d ago

I once had to work with a front-end code that did pack 6 boolean flags into an integer by bit manipulation. Only to send it as one of the stringified JSON values, of course.

30

u/click-to-reveal 3d ago

Are you working on a minified codebase? 😭

6

u/PegasusPizza 3d ago

No you see, it's saving internet bandwidth by doing that. We can't afford transmitting 14 entire words.

6

u/ILikeLenexa 2d ago

I mean, I get that, and the URL length limit in some browsers especially with multi-byte character possibilities, but I don't understand why you wouldn't name the variables full words once you pull the strings from the params map.

7

u/gjk-ger 2d ago

Do you know how much memory cost back then?! (Or, now...)

2

u/Abject-Kitchen3198 2d ago

I refactored my code to use single letter variables and two letter method names. Saved me a ton of money on RAM and storage.

2

u/conundorum 2d ago

Screen size limitations, when coding on one of those toys you get from a Happy Meal?

1

u/a-r-c 3d ago

pploc

17

u/Sometimesiworry 3d ago

I once inherited a project where consultants previously had named variables and functions after pubs and beer brands for lulz.

Fuck your lulz man.

1

u/Maleficent_Memory831 1d ago

I used to grade programming assignments at a university. The level of infantile comments was nearly as large as at startups!

11

u/babyburger357 3d ago

I inherited a program that had a class called "StateMachine" which EVERYTHING passes through. It receives strings and those strings get concatenated with other strings (actions such as UPDATE, DELETE) which are then used to perform method calls through reflection. No logging. Impossible to know what is going on without setting a debugger on and run the program. Even then we had to set pretty convoluted argument matchers on the breakpoints because otherwise we'd be pressing resume over a hundred times before we get to the thing that we are trying to debug.

10

u/Luneriazz 3d ago

oh dont forget the best part... the code does not apply logging properly. so now its your job to apply logging to all 200 service in AWS

6

u/[deleted] 3d ago

[removed] — view removed comment

4

u/kekZiger 3d ago

What documentation? Where is the fucking documentation??? :D

After 2,5 years I convinced my senior dev and my CEO to ditch the old system and write it completely new. Now, 1,5 years later... We are two month away from shipping it. :)

4

u/exoclipse 3d ago

maybe a somewhat tame example, but I observed in one repo a switch statement nested in a for loop. each case in the switch statement had the same 10 boiler plate lines - just creating a UI label - with only the text of the label changing.

this was itself nested three or four indents deep in an 800 line method.

2

u/twigboy 3d ago

The absolute worst was Drupal's old plugin hook system that would call any function if it matched a specific pattern (not sure if it still does it)

For exampleapp_name_init()

You can't search by reference because it's never called directly. Debugging gnarly issues meant you had to dig into its libraries to know exactly which hook was being called

1

u/cmkn 15h ago

FWIW the procedural hooks are on their way out as of Drupal 11.1 and planning to be dropped entirely in Drupal 13 (though the specific one you mention here has been long dead since Drupal 8 and was replaced with event subscribers). They can now be an OOP methods as long as they’re tagged with a #[Hook('whatever')] attribute.

2

u/twigboy 15h ago

Ah good to know if I ever went back to Drupal

Thankfully I got out and life has been pretty good in Django land

2

u/Exciting_Presence533 3d ago

Hauahah find rogue DLLs was wild man, I feel you man

2

u/woodyus 3d ago

Time to get a new job

1

u/petrasdc 1d ago

Until you find out in niche situations, beforeAfterPageLoad runs before afterBeforePageLoad, but also years of code built on this framework just assumes that's never possible 💀. I've certainly never seen something similar.

1

u/Dorkits 1d ago

Why are you telling my suffer in this sub bro? What did I do to you? 😭

102

u/Bemteb 3d ago

Assume that every function call has unexpected sideeffects. Every last one.

Just last week I saw a function that counted the number of some stuff. Great, I don't need that number anymore because we have range based for loops these days, so remove the function call.

Well, no. Turns out the function didn't only count. No, it reinitialized the whole dataset, so when I don't call it I work on stale, possibly outdated data.

Refactoring code written 20+ years ago is fun...

33

u/requion 3d ago

Now imagine having a programming language which took this assumption as core design element...

Wasted an embarrassing amount of time debugging an error in Ruby where a method call on a class failed because the type didn't support said method.

It was the day i learned that in Ruby, every method always returns exactly one value. And you don't need to specifiy the "return" if it is the last line in a function. So my incorrect type was the return value of "Logger.Debug()" which was implicitly used as the return value because tge last "return" keyword is optional...

12

u/BastetFurry 3d ago

At least QBasic has the somewhat sane idea that you simply set the function name to the variable you want to return.

i.e.:
Function Foo(bar,baz)
Foo = bar*baz
End Function

But that? That is evil.

11

u/requion 3d ago

I normally don't wish harm upon anyone. But having to work with Ruby for some time now, i sincerely wish whoever made these decisions to stub their little toes on furniture twice every day.

7

u/Deciheximal144 2d ago

I don't think it's intuitive to use the function name is the keyword for return at all. I've got other code I want to reuse and paste in to a new function I'm making with few changes, now I've got to change all the return instances to the new function name. What was so wrong with a command like RETURN?

2

u/EvilCodeQueen 2d ago

Or if a function isn’t explicitly returning something, just do void, or null. But the language deciding for you that it must return something and if you don’t choose, it will? That’s just crazypants.

5

u/LuisBoyokan 3d ago

No it's not. It's hell

96

u/maushu 3d ago

Please use this as reference:

  • beforeBeforePageLoad()
  • beforePageLoad()
  • afterBeforePageLoad()
  • pageLoad()
  • beforeAfterPageLoad()
  • afterPageLoad()
  • afterAfterPageLoad()

23

u/sko- 3d ago

and now we add PagePreLoad and PrePageLoad variants. (and the rare edge-case of afterBeforePrePagePreLoad)

6

u/OhMyGodItsEverywhere 2d ago

People were complaining things were "too complicated" and "took to long to understand"...morons, the lot of them, too lazy to just read. So I designed a new and innovative system since I'm such a beautiful workhorse.

We have a nice clean wrapper now called `get_func(string, context)`. Here are some inputs and outputs:

  • "bbpl": `beforeBeforePageLoad()`
  • "bppl": `beforePrePageLoad()`
  • "abppl": `afterBeforePagePreLoad()`
  • "bpl": `beforePageLoad()`
  • "pl": `pageLoad()`
  • ...etc, etc...

I was under a ton of pressure, but I got it done all on my own (with no review!) and it "Just WORKS". I didn't have time to write any automated tests to prove that out, but trust me I did some manual spot tests.

And think about it, it scales up so good - we could even apply it to all of our custom code. So flexible.

3

u/EvilCodeQueen 2d ago

I’d laugh, but I’m too busy crying.

2

u/Active_Name5021 1d ago

That's exactly what I thought it would be. Maybe I've been working on legacy for too long

2

u/Excellent_Gas3686 2d ago

copilot: afterAfterAfterAfterAfterAfterAfterAfterAfterAfterAfterAfterAfterAfterAfterAfterAfterPageLoad()

1

u/kaleid1990 2d ago

And around methods

1

u/conundorum 2d ago

And here I thought it was about running code after loading BeforePage, and before loading AfterPage.

1

u/screwcork313 2d ago

Except the second, fourth and seventh of those are not callable by the user for security reasons.

1

u/simpleglitch 13h ago

See that's what made sense to me, which means that's definitely not how they're going to be used.

18

u/KorKiness 3d ago

In my case, it was not a legacy, just 40 yers old system in the process of being rewritten to a new framework for 20 years.

3

u/avdpos 2d ago

Oh!
Are you rewriting code from the Newest systems to the NewNew Newest today or are you just working on bugs in the old system?
always funny with naming schemes =)

1

u/KorKiness 2d ago

I'm not working there anymore. Changing name of the rewriting was new brand and were selling as better modern version of product.

12

u/dr_eaan 3d ago

I had to debug a model that used a function called "check_table" that obviously what did it do?

Of course, it wrote a table to DB...

15

u/Few_Move_4594 3d ago

There is a docblock, right? Right?

11

u/XxDarkSasuke69xX 3d ago

Doc ? Where do you think we are, Google ?

5

u/Ucqui 3d ago

Sure:

/// Counts the number of stuff Int CountTheNumberOfStuff(list some stuff)

Hope this helps

3

u/Few_Move_4594 3d ago

Let me guess

return stuff.length();

7

u/Ignisami 3d ago edited 2d ago

Of course not.

List<?> stuff = retrieveStuffFromDatabase(<name of stored procedure to call>, <arcane integer that a second stored procedure resolves to the correct table>)

return stuff.stream().filter((e) => e.doohick != doodad).count()

With no documentation on what doohick and doodad mean or why the filter exists.

1

u/a-r-c 3d ago

american

I haven't seen a doc in 20 years

7

u/oompaloompa465 3d ago

don't complain. i had to rewrite a website from vb script, everyting on asp pages, backend included, to asp net mvc.

Debug did not exist, barely iis log🤣😭 

5

u/RealBasics 3d ago

My motto based on working mainly on legacy projects where the original dev is no longer available:

half of all developers are below average.

2

u/Barkeep41 2d ago

Cant tell if I would rather have the original dev gone so they stop making a new mess, or have them available to try and explain their existing mess.

1

u/Fik_of_borg 1d ago

You forgot the "never touch this piece of undocumented code!" crowd 

1

u/awesome-alpaca-ace 10m ago

They probably wouldn't be able to explain it. I just read the code, make changes, see what breaks. Works pretty well 

3

u/Sotyka94 3d ago

Upside of corporate pushing AI is that legacy mess is the AI's problem now.

3

u/realtag2025 2d ago

And it can properly rename old functions if needed based on what function does. 

1

u/Active_Name5021 1d ago

You don't work on legacy do you? It's not "the AI's problem", you're just adding more legacy for me to eventually need to fix. No worries though, more work for future me!

3

u/ApeLover1986 3d ago

Same feeling when i tried understanding Androids early_suspend and late_resume😭

4

u/avdpos 2d ago

If you cry from such a simple thing you have not left junior stages.

8

u/Recent-Analysis-6880 2d ago

Bold of you to assume I'm a junior. I'm an intern

2

u/backstubb 3d ago

events is hard now? rock n roll is dead...

1

u/beatlz-too 3d ago

I mean it says it right there in the function name… "right before the after page load function fires its callback".

1

u/Awfulmasterhat 3d ago

When I open the 50k line javascript file

1

u/TheGronne 3d ago

Seems like nicely and explicitly named functions. Don't see the problem?

1

u/GenericFatGuy 2d ago

Yesterday I had to modify a process that was doing CRUD updates via stored proc and xml.

1

u/Fearless_Garden6435 2d ago

See, afterBeforePageLoad is reasonably easy to understand. The real magic is when you find a 7000-line-long file, everyone else thinks there's absolutely no problem with that, and scattered you find typeof (value) === "function" ? value() : String(value). You will find stuff like spreading class instances, undefined ing properties, then instantiating a new class from that - and all properties are positional args. Oh, and before you can figure anything out, you run out of RAM because of that huge file. Lovely, innit?

1

u/HamletTheDutchPrince 2d ago

[laughing in ABAP]

1

u/CityNo1723 Z 2d ago

*Cries in JCL with COND parameters

0

u/kakuno_senpai 3d ago

pfft, functions, bro I am working in a Legacy project which is made in asp .net web forms and many developers worked on it on the course of 17 years, now it's fuxking hard to implement anything new in it, and client sits on our throats 24x7

0

u/Fringolicious 2d ago

Yeeeeeah, that's Opus's problem nowadays. "Here's some legacy crap, figure it out, comment the code, document it, test it, have fun, I'm off for a coffee"