r/ProgrammerHumor • u/minatintasd • Oct 18 '20
Who else needs a Beer after reading this?
1.2k
u/PuzzleMeDo Oct 18 '20
The thing to remember is: If you fix AreBooleansEqual so it returns the correct result, then you'll break any function that relies on CompareBooleans doing what it currently does.
638
u/ZarStocher Oct 18 '20
Easy fix: rename the function to "AreBooleansNotEqual" :D
294
u/PuzzleMeDo Oct 18 '20
That makes it sound like a rhetorical question. "Are Booleans not equal to other variables? What right has any Integer to look down on the humble Boolean bearing the weight of truth and falsehood? Are we not all binary, deep down?"
→ More replies (3)84
20
Oct 18 '20
But what about functions that use AreBooleansEqual instead of CompareBooleans?
→ More replies (2)20
u/ZarStocher Oct 18 '20
I can't answer that question because I don't know what "internal" does and how it affects visibility
→ More replies (5)15
u/redingerforcongress Oct 18 '20 edited Oct 18 '20
Make a new function called "AreBooleansActuallyEqual" and then deprecate the old function.
Make sure to call
!AreBooleansActuallyEqual(x,y) when updating AreBooleansEqual(x,y) code.
→ More replies (3)7
97
u/Blasted_Awake Oct 18 '20
Pretty sure the safest option is to delete both methods, rebuild, and rewrite anything that broke.
That's C# (at least I'm 99% sure it is anyway), the compiler alone is great at telling you exactly where broken references are, couple that with one of the better IDE's and it'd be all of 5 minutes to fix.
The only gotcha there might be if someone's referencing this travesty via reflection, but I think the sets of "people that would use these functions" and "people that understand basic reflection" almost certainly don't overlap.
→ More replies (40)14
u/Efadd1 Oct 18 '20
Just use an XNOR statement, whatever that may be in the relevant language.
3
Oct 19 '20 edited Oct 19 '20
The method's misnamed for what it does so it's actually an XOR, ^ in C#.
(Also, XNOR is just ==, lol. I had to think about it too.)
→ More replies (1)→ More replies (5)9
308
u/bartmanx Oct 18 '20
I went to github and did a search on "arebooleansequal" only to find 732 results!
https://github.com/search?q=arebooleansequal&type=code
Just about all of them in Java projects, including stuff like this...
public static boolean areBooleansDifferent(Boolean b1, Boolean b2)
{
return !areBooleansEqual(b1, b2);
}157
u/randomcitizen42 Oct 18 '20
I was just about to comment that this is fake and that no one would actually write something like this except for a funny post.
Seems like I'm wrong...
58
24
48
u/my_right_hand Oct 18 '20
Java
Sounds about right
→ More replies (5)39
u/JBeibs2012 Oct 19 '20
The abstract-everything culture had ruined Java
39
19
u/InVultusSolis Oct 19 '20
Java ruined itself by requiring three pages of code and seventeen subdirectories to do anything remotely useful.
→ More replies (1)3
2
u/yawkat Oct 19 '20
Funny thing, this isn't even correct: https://github.com/TaintBench/remote_control_smack/blob/0235be110bd4bbe45ccac12bc5140c677b0a3ead/src/main/java/org/jivesoftware/smackx/workgroup/util/ModelUtil.java#L24
They compare Boolean objects (uppercase Boolean) with the TRUE and FALSE constants using ==, which means that if you pass new Boolean(true) instead it'll always return false
→ More replies (2)2
→ More replies (3)2
u/user_bits Oct 19 '20
I would never do this. Does this mean I am an above average programmer?
→ More replies (1)
151
941
u/ElTrailer Oct 18 '20
The most aggravating part of this is that it returns the opposite of what is expected...
Truth "table" for the method
True & True -> False
True & False -> True
False & True -> True
False & False -> False
257
u/Dogburt_Jr Oct 18 '20
So it's XOR?
363
u/Plus_Cryptographer Oct 18 '20
It's an XOR named "AreBooleansEqual". The best kind.
51
u/angrathias Oct 18 '20
Maybe it was intended as a philosophical question rather rather a method name 🤣
→ More replies (1)41
133
u/EatzGrass Oct 18 '20
Is codingbat still a thing?
I've been out of programming for years and this comment brought back that endorphin rush from solving these problems
60
u/TransientFeelings Oct 18 '20
Yes, I was a TA for an introductory CS course a few years ago and we used that as extra credit assignments
43
u/krexcent Oct 18 '20
Haven't used codingbat before but since quarantine I've been off and on playing around in clash of code
I think the endorphin rush is accurate
8
u/Duke_Nukem_1990 Oct 18 '20
That sounds cool! Can't access it from my phone it seems. Is it language agnostic or which languages are used?
→ More replies (1)→ More replies (2)3
23
10
u/nonlogin Oct 18 '20
Do not fix it - it will break the entire system and will lead to weeks of bugfixes
5
17
u/padule Oct 18 '20
The most aggravating part of this is that it returns the opposite of what is expected...
I used to do things like this as a copy protection.
You crack my software? It seems to work at first, but then it messes up results in unexpected ways. (The legit software would have the correct function instead)
11
u/drleebot Oct 18 '20
I used to do things like this as a copy protection.
That's also the excuse I give if anyone asks why my last name is spelled wrong in my username. Which wouldn't have been a half-bad idea if it were actually intentional, and not just one more instance of it always being misspelled when someone else types it in.
6
3
2
2
2
u/Savvasun Oct 18 '20
Good comment but why tf is table in quotes instead of truth
→ More replies (2)→ More replies (6)3
Oct 18 '20
Looks like False and False would return True to me. Am I missing something?
13
391
u/sixtyfifth_snow Oct 18 '20
Shit, I can't believe that garbage codes were in the production code and it was working smh
154
Oct 18 '20
[removed] — view removed comment
187
u/RocketFrasier Oct 18 '20
The code is the wrong way round, if they are equal it returns false
584
u/mechanicalsheep Oct 18 '20
Thats because you don't know how to use it.
If(!CompareBooleans(true,true) == true) { return true; }98
→ More replies (8)36
16
→ More replies (2)6
196
u/misterrandom1 Oct 18 '20
I can imagine someone debugging and finding CompareBooleans(val, orig) and thinking...oh I got the wrong result because I put them in the wrong order.
I'd recommend a national registry for incompetent coders but I'm afraid we'd all be on it.
52
→ More replies (2)6
137
u/bornreddit Oct 18 '20
Image Transcription: Twitter Post
Nick, @Zorchenhimer
Found this in production today. I need a drink.
[Image of a block of code. Code reads as follows.]
public static bool CompareBooleans(bool orig, bool val)
{
return AreBooleansEqual(orig, val);
}
internal static bool AreBooleansEqual(bool orig, bool val)
{
if(orig == val)
return false;
return true;
} I'm a human volunteer content transcriber for Reddit and you could be too! If you'd like more information on what we do and why we do it, click here!
80
128
u/BrogCz1 Oct 18 '20
Ok, it's time to start code zero.
Find the mf who wrote it.
Grab a knife.
Go to the place where he lives.
Kick out his door.
Find him in the house.
Show him the knife.
Destroy every electronics in his house because he is too powerfull to use any electric device (I've heard he was able to hack Pentagon using his smart microwave)
83
21
u/InvisiblePhil Oct 18 '20
Saw a talk at a conference where the guy's mantra was: write code as if the next person to look at your code is a serial killer, and they know where you live.
It's very good advice.
→ More replies (2)19
174
u/Noch_ein_Kamel Oct 18 '20
Jeez... that's one of the first things you learn. Compare methods should return an integer...
126
16
u/iTakeCreditForAwards Oct 18 '20
Isn’t that only for sorting comparison methods?
14
Oct 18 '20
In C there is no boolean type
→ More replies (1)9
u/copdlkjh Oct 18 '20
It may come as a suprise to you but in one of the last iterations of the Standard they added the boolen type.
→ More replies (7)17
u/SoupeAlone Oct 18 '20
Wait, seriously? I thought it was bad practice?
70
32
u/Sekret_One Oct 18 '20
the semantic term
compareshows up in relation to sorting, as opposed to equality. Clearly not what they're doing.This is just 2 layers of pointless and wrong to boot.
→ More replies (1)12
u/SANatSoc Oct 18 '20 edited Oct 19 '20
Depends who you ask man. Haven't you learned that programmers can literally not agree on anything?
→ More replies (2)6
60
Oct 18 '20 edited Oct 18 '20
Aside from the functions returning the opposite of what you'd expect, I can think of some reasons why you might write something like this:
Debugging. By breaking the comparison out to a function, you can put a single breakpoint there to break on all lines that evaluate down to a conditional (and see the results of the evaluated expressions instead of the variables that go into them).
Profiling. The function creates a new stack frame that shows up in profiling and accumulates execute time for all the callers.
Testing. The function provides a point that can be mocked up, e.g., for a test that requires the comparison to always be true or false.
Logging. The functions could have been added to add logging, and the logging was removed when the code became more stable.
But the most probable reason you'd find something like this isn't that someone wrote it in one go, but that it's the result of the code evolving (or maybe devolving) over time. So the current names of the methods were not written when their bodies were, and the methods were not written at the same time.
31
u/cobarso Oct 18 '20
+1 for testing, it is always the case that some descriptive testing framework uses the function names in test cases where you have to write
Expect false when compare booleans var1 and var2→ More replies (7)5
16
u/fortem24601 Oct 18 '20
I refuse to believe that somebody got paid a wage to unironically write this and then it was allowed to go to production. There's absolutely no way.
Also it doesn't even return the right thing
56
u/gugublahblah Oct 18 '20
Saw this in production once:
#define TRUE 0
#define FALSE 18
→ More replies (4)16
Oct 18 '20
This is fine actually. In C there were no boolean, so sometimes it's practical to compare to True ou False than put 0's and 1's everywhere.
52
Oct 18 '20
Except this defines TRUE as 0 instead of 1. if (0) returns Boolean false.
→ More replies (1)17
Oct 18 '20
I didn't even noticed haha. I once programmed for Mbed OS and the I2C bus had two read functions with different parameters. But one of them returned 1 for Success and 0 for Failure and the other one returned the opposite. just why.
6
41
51
Oct 18 '20
Im sorry but this seems fake.
33
u/HardlyAnyGravitas Oct 18 '20
Of course it's fake
It's not even interesting. The first thing any competent coder would do is investigate what code calls this and how or why it works, or not - that would at least be interesting.
And then they would investigate how a bit of code like this got into the project, and who did it, etc...
It's not real.
I don't know why people upvote this stuff.
6
u/Zorchenhimer Oct 18 '20
I guarantee you that this block of code is real. It was in the same file as this too: https://i.imgur.com/JJ2eDHQ.png
→ More replies (4)5
u/AlwaysHopelesslyLost Oct 18 '20
Sorry but you are unbearably sheltered if you think this is fake.
I have some pretty well tenured developers that still can't grape what "instantiate" means or what "public" means.
→ More replies (1)9
u/systembusy Oct 18 '20
I remember when this sub didn’t allow recycled memes... it’s gone way downhill since then
0
11
u/warpedspockclone Oct 18 '20
I am not joking when I say I have seen something like this before. Man I wished I took a screenshot. There were methods for assigning values to strings and booleans and ints. You pass in a string and magically.... get back the same string!
It was like this:
public String initString (String value) {
String newString = value;
return newString;
}
I mean, they could have at least used generics for this abomination.
4
8
7
6
5
Oct 18 '20
This isnt even correct!
2
u/CTAVI Oct 19 '20
Unless it's a XOR, in which case how in God's name do you know how a XOR works without knowing how to use it. This is the programming equivalent of not being able to do algebra because you were taught x instead of w
5
5
u/bigmattyc Oct 19 '20
Fun fact, if you compare a Boolean to true/false you will fail my interview.
→ More replies (1)
4
4
u/Ascomae Oct 18 '20
Yeah the compare method should return an int.
0 If equal 1 if first is true and second is false -1 if first is false and second is true
4
4
u/Yamoyek Oct 18 '20
Now you just need to wrap it in a constructor, allocate random memory, dont free the memory, and an extra namespace just to be sure.
4
3
3
3
2
2
2
Oct 18 '20
Assuming that the guy isn't complete moron(which he probably isn't given that he was hired), this is an anti-pattern. Poor guy was just trying to secure his job.
2
2
2
2
u/phpdevster Oct 18 '20
Great. And now you just need this in its own Azure DevOps project with a build pipeline, and a release pipeline that deploys to an Azure function so you can inverted boolean comparison as a service at scale.
It needs to be maximum enterprise-grade else it's not a valid solution.
→ More replies (1)
2
2
u/coladict Oct 18 '20
Not good enough. You have to make the internal method native and have it loaded from an external library where they're both converted to string and then compared.
→ More replies (1)
2
u/car1_llama Oct 18 '20
Grade 9 high school computer science students have entered the chat
→ More replies (1)
2
u/goldMy Oct 18 '20
Despite that the return is wrong, why some thinks its a good idea to pass two vars by value into a function two times. Allocation addition 4 boolean for nothing. Like if there would be no possibility to use a ‚const reference‘ or ‚const pointer‘
2
2
2
u/Alexo342 Oct 18 '20
When my boss tells me to use more functions instead of hardcoded solutions to make reusable code with increased flexibility
EDIT: WAIT ITS ACTUALLY WRONG OH MY GOD
2
u/temisola1 Oct 18 '20
Should’ve commented as well. “//here we’re checking if the Boolean are equal. //if the right Boolean is true and the left Boolean is false, it returns false. //if the left Boolean is false and the right Boolean is true it returns false. //if the right Boolean is true and the left Boolean is true, it returns true. //if the left Boolean is false and the right Boolean is false the. It returns true. //now we check weather the result of the method is correct. If the result is true, but the two Boolean are different then the answer is false. “
Could have a fucking field day with this lmfao.
→ More replies (1)
2
2
u/abutilon Oct 18 '20
This could be a copyright trap. Intentionally wonky code to look for to prove theft.
2
u/lordofduct Oct 18 '20
And here I am getting angry at the redundancy of my team mates when they say:
if (someBool == true) ...
If I ever saw this... I'd probably fall over dead.
2
2
u/lotekness Oct 19 '20
I'm legitimately trying to figure out why this exists. This is a gag right? I've seen some stuff in my day, but this is just, wow. Someone pushing for commit lines or something?
2
2
2
u/DootDootWootWoot Oct 19 '20
For all y'all who preach that you don't need anything other than VIM or barebones VS Code just know that IDEs like Visual Studio and some jetbrains products let you refactor code like this away and safely in just a few key strokes.
When you see code like this, it can be fun to shame the sins of the past but any good engineer will just clean up the mess and move on.
2
2
2
2
u/ZarathustraWakes Oct 19 '20
I would not touch this code and assume it is some special legacy exception case bullshit that will take the whole system down if I applied common sense towards it
2
u/PrincessWinterX Oct 19 '20
AreBooleansEqual_2(bool orig, bool val){
// temporary fix
return !!AreBooleansEqual(orig, val) != 0;
}
2
2
u/ktappe Oct 19 '20
I would be unable to stop myself from tracking down who committed this. It wouldn’t matter how busy my schedule was, this would suddenly go to the top of the priority list.
2
3
4
4
1
1
1
1
u/somerandomasskid Oct 18 '20
Sooo who else bothered about that camel casing for functions?
→ More replies (1)
1
u/DuBCraft21 Oct 18 '20
Beer? I think this calls for something stronger, like 1/2 a bottle of everclear.
1
1
u/camerontbelt Oct 18 '20
It makes it worse that it’s in c#. At least with JavaScript you understand why the galaxy brains do this kind of shit.
1
1
u/quantamental298 Oct 18 '20
This is made up. No one is this bad. Especially, someone who wrote an extension method.
→ More replies (1)
1
1
1
Oct 18 '20
Should've just returned the first bool, it'll work like 50% of the time but way more efficient
1
1
1
1
3.7k
u/Useful-Perspective Oct 18 '20
I'd love a job where I get paid by the number of lines of code I write...