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 š¤®
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.
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.
Or the PHP code where someone has a series of if/switch statements to build up a function name piece by piece, and then calls the string to execute the function. Yes, putting a string in a variable and calling it is real in PHP. And yes, itās terrible idea
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.
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
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.
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.
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. :)
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.
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...
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.
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?
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.
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.
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 =)
List<?> stuff = retrieveStuffFromDatabase(<name of stored procedure to call>, <arcane integer that a second stored procedure resolves to the correct table>)
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!
Iāve heard of codebases where functions were named after cereals. I always wanted to work in one of those, it sounded fun. Instead I got pxCalcNewV3 and mxCalcLegacyOld instead. No one knew what the px and mx prefixes meant since the dev who first wrote the code been fired before his replacement was hired. Suffice to say no knowledge transfer had happened. But, everything had them (functions, variables, classes). Everyone just kept using those prefixes without knowing why they existed just to match ācode styleā (though no one agreed when to use each prefix). And also because there was a PHP file autoloader that enforced the existence of one of those prefixes for some classes - but only some classes. Most classes didnāt need them
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
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"
4
u/avdpos Sep 30 '26
If you cry from such a simple thing you have not left junior stages.
385
u/Signal-Permission394 Sep 30 '26 edited Sep 30 '26
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 š¤®
112
u/Bemteb Sep 30 '26
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...
104
u/maushu Sep 30 '26
Please use this as reference:
18
u/KorKiness Sep 30 '26
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.
13
u/dr_eaan Sep 30 '26
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 Sep 30 '26
There is a docblock, right? Right?
6
u/RealBasics Sep 30 '26
My motto based on working mainly on legacy projects where the original dev is no longer available:
5
u/Sotyka94 Sep 30 '26
Upside of corporate pushing AI is that legacy mess is the AI's problem now.
8
u/oompaloompa465 Sep 30 '26
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š¤£šĀ
3
u/ApeLover1986 Sep 30 '26
Same feeling when i tried understanding Androids early_suspend and late_resumeš
2
u/Awfulmasterhat Sep 30 '26
When I open the 50k line javascript file
2
u/GenericFatGuy Sep 30 '26
Yesterday I had to modify a process that was doing CRUD updates via stored proc and xml.
2
u/Tofurama3000 Oct 04 '26
Iāve heard of codebases where functions were named after cereals. I always wanted to work in one of those, it sounded fun. Instead I got pxCalcNewV3 and mxCalcLegacyOld instead. No one knew what the px and mx prefixes meant since the dev who first wrote the code been fired before his replacement was hired. Suffice to say no knowledge transfer had happened. But, everything had them (functions, variables, classes). Everyone just kept using those prefixes without knowing why they existed just to match ācode styleā (though no one agreed when to use each prefix). And also because there was a PHP file autoloader that enforced the existence of one of those prefixes for some classes - but only some classes. Most classes didnāt need them
2
u/backstubb Sep 30 '26
events is hard now? rock n roll is dead...
1
u/beatlz-too Sep 30 '26
I mean it says it right there in the function name⦠"right before the after page load function fires its callback".
1
u/TheGronne Sep 30 '26
Seems like nicely and explicitly named functions. Don't see the problem?
1
u/HamletTheDutchPrince Sep 30 '26
[laughing in ABAP]
1
u/portareset1 Oct 01 '26
lmao
1
u/Mr_Rogan_Tano Oct 04 '26
Fuck it. Claudio, come here
0
u/kakuno_senpai Sep 30 '26
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 Sep 30 '26
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"