That's not even the worst part. What the fuck does a function named Compare_anything do? Does it return anything? It sounds like nothing but a side effect.
Usually comparison functions are supposed to return an integer and are usually useful for sorting. However this one returns a bool so it's both useless and terribly named.
Management: Gee whiz, we really have no idea how to gauge productivity to decide who gets promoted. We could manage. Or, better, we could just have someone write a script that pulls info from git on how many lines of code each person has written.
I'd give my right hand this is a code review problem. Someone extracted a method returning true false. Then an intern came along and was told to refactor. They saw a lot of comparisons and "extracted" them.
My boss's boss, a former Ops manager who liked to keep track of system stats, once asked her why the CPU usage on the dev box had decreased that month. Weren't the devs doing any work?
I was debating on bitwise operations, but decided on super basic if statements which I think the compiler would optimize, happy to see the logical operation form too
I should have created a local variable to store the result variable and return after the if statements. I just couldn't help to make it look partially nice. My brain just doesn't think at this high caliber of LOC optimizations.
var CompareBooleans = new ComparatorFactory().BooleanComparator(new BooleanComparisonByEqualityPolicy());
if (CompareBooleans(a, b) == true) {
System.Out.PrintLn("Sames!!!");
}
...
But now that I've written this, it's C#, so it's missing dependency injection.
My guess to why there’s two functions is because it was originally only internal, and the programmer realized they needed public as well, but changing internal to public is too scary so they created a new method instead.
We affectionately called it "subscurity" on the FE team.
When our BE apis would not give us any information why something failed, nor would they give us access to their logs. Complete black box of undocumented doodoo, and they would proudly say "security through obscurity" every time we asked why they couldn't make improvements to usability.
I’ve asked ChatGPT to create boiler plate code and it will offer these nested functions so you can change the logic in the future. It’s not smart enough to ask why you’re doing something a particular way or suggest a better alternative.
For the correct OOP solution, you would need consider whether this can be thought of as a kind of stateless leaf method, and therefore implement it as an abstract (singleton) factory, but on the other hand, if you're using a context object with the registry pattern, you should probably do this properly with IoC containers. Of course, if your object graph isn't too complex or entangled, you could always just do constructor injection but you risk manging your unit tests, so I would go cautiously if I were looking in that direction.
I know. I didn't say this was OOP, I said this was your brain when you OD on OOP. While we are not dealing with objects, I'd argue that the kind of approach that would lead one to needlessly overcompartmentalise code like this is the product of having a little too much OOP.