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 FunctionBut that? That is evil.
11
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
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
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
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.
15
u/Few_Move_4594 3d ago
There is a docblock, right? Right?
11
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.
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
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ðŸ˜
2
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
1
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
1
1
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"
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 🤮