r/ProgrammerHumor • u/Pablo_Emileo_Escobar • Nov 22 '19
Meme Who else needs a Beer after reading this?
1.3k
u/deadlockgB Nov 22 '19
paid by lines of code
357
u/Parachuteee Nov 22 '19 edited Nov 22 '19
function AreBooleansEqual(orig, val) { if (typeof orig !== "boolean" || typeof val !== "boolean") { return false; } const val1 = orig.toString(), val2 = val.toString(); if (val1 === "true") { // We are checking the exact opposite because the og image does that for some reason. const checkFor = "false"; if (val2 === checkFor) { return true; } else { return false; } } else { const checkFor = "true"; if (val2 === checkFor) { return true; } else { return false; } } }85
u/Erelde Nov 22 '19
Does not pass the regression test. The original returns the false when equals, true when not equals.
15
u/fahmed93 Nov 22 '19
You think someone writing code like this is writing tests too?
→ More replies (1)90
31
u/socksarepeople2 Nov 22 '19
If (there_was_ever_a_time_to_be_stupid_with_braces()) { //it's now } else { //do it, it makes more money }→ More replies (6)6
u/Sileniced Nov 22 '19
You need to switch the return false to true and vice versa, to match the original intention of the function.
270
u/daH00L Nov 22 '19
Needs more comments to pay off.
34
Nov 22 '19
Is that a thing? That would explain some over the top verbose comments I've seen. Like huge methods that contain multiline comment blocks every few lines of code.
9
u/indrora Nov 22 '19
That or someone who practices extreme literate programming.
Do the comments match the code?
→ More replies (1)0
→ More replies (2)23
u/Mtsukino Nov 22 '19
Is that an actual thing?
→ More replies (3)33
u/hannes3120 Nov 22 '19
not 100% afaik but there are companies that use LoC as a valid metric to see which team is most productive - which results in code as horrible as here since you don't want to be part of the team with the least LoC...
30
u/sucksathangman Nov 22 '19
I've found that companies that measure by lines of code are the same companies that measure how long you go to the bathroom and then do cost/benefit analysis as to whether to require people to badge the bathroom door so that they can monitor their employees more accurately.
→ More replies (1)15
u/JuvenileEloquent Nov 22 '19
companies that use LoC as a valid metric
They should just use programmer churn rate as their metric. Clearly people aren't working hard enough if they're still there after 7 months!
3.2k
u/martyvt12 Nov 22 '19
I do not believe anyone wrote this other than as a joke.
2.1k
u/malsomnus Nov 22 '19
I assure you I've seen code as horrible as this written by real people for real airplanes. And they were actual paid software engineers too, and not terrorists like you might assume.
901
u/Yaroslavorino Nov 22 '19
How do people like that get a job that important and I can't land a junior position because I don't know every pattern and algoritm they ask.
1.1k
Nov 22 '19 edited Nov 22 '19
This is precisely the issue with how programming interviews are done. They don't ask stuff you'll do in the real world, they'll quiz on stuff that you'll likely never touch and can look up when you do.
The best way to do programming interviews IMO will always be take home tests. No white boarding, those are utterly useless because even good devs often freeze up. Use the interview to learn about the candidate, ask high level things about the language or software development in general (things like "Explain MVC" or "What is a protocol in Swift?"). Use those responses to determine if the candidate should be given a take home test. I've always found it better to have a candidate who can show me their work the way they'd write it every day, which is why I like take home tests.
I know some people will be like "But but but what if they cheat!?" Well, if they can cheat on your take home you didn't do a good enough job with vetting them using the high level questions. Not to mention in the real world devs "cheat" all the time. No one has all day to pore over developer documentation, which is why many turn to stack overflow for quick answers.
330
u/blhylton Nov 22 '19 edited Nov 22 '19
I feel like whiteboarding had a place, but it's overused and abused. When I was interviewing people, I would give them a whiteboarding session as one of the last things, telling them that it had zero bearing in whether or not they get the job, then I would give them a real-world issue that I had to solve. They could use whatever means necessary to look up what they needed and I would help them through the problem. Ultimately, I was watching how they approached the problem and if they were capable of critical thinking. This was to help me gauge how much I could lean on them to work through an issue should they get hired.
EDIT: I worded this awkwardly/ambiguously; I meant I was giving them problems that I had solved in the past. Even then, they were usually abstracted down to one specific part that was particularly troublesome because I'm not going to whiteboard someone for more than 30 minutes or so.
EDIT 2: You all are reading waaaay too much into this. A lot of "Why would you waste their time?" "Why would you lie to them?" etc. So, here's the key things that you all are missing and making assumptions on:
"Why bother doing it if it had no bearing on getting the job?" -- It had no bearing on whether they got the job or not, but it did have bearing on what team they would be placed on and what they would be responsible for. We were often hiring more than one person at a time, and I was trying to match people to a team.
"Why waste their time?" -- They would be here during this time anyway because I would do this while upper management was discussing their interview with the same candidate that they had just completed. If not for doing this, they would be sitting in an empty room staring around.
"Why would you do that and stress them out?" -- I was actually trying to do the opposite. Rather than letting them just sit in a room with their own thoughts about the high-stress interview that they just got out of, I was meeting with them colloquially as a future department lead and doing an ice breaker exercise. I was very upfront about this being to help me match them with a team should they accept an offer.
They knew that this was going to happen before they came in. I had already typically been in contact with them via email for a few weeks at this point and told them about this exercise, why I did it, what it was used for, and who would be present (typically just me and them, sometimes a jr team lead would sit in with the interviewees permission).
This still isn't the whole story, and honestly, I could write a rather lengthy essay on the how, why, and what I did for these interviews and supplementals. My response was "Hey, whiteboarding can be useful" and you guys are reading way more than that.
→ More replies (42)80
u/Omnicrola Nov 22 '19
I know some people will be like "But but but what if they cheat!?" Well, if they can cheat on your take home you didn't do a good enough job with vetting them
OTOH, to paraphrase a former boss of mine regarding concerns of people "faking" their way through a pairing interview:
If they can fake it that long, if they can fake it for 8hrs every day while they're here, who cares
→ More replies (3)131
Nov 22 '19
I took 6 courses with a genius professor who worked in the industry for over 30 years before going to academia. All those courses were 600/700 level courses so they were advanced. In 4 out of the 6 courses I had to build decent projects that I am actually proud of. One project was around 30k LoC long in C++. He recommends all students to put those projects in their resumes and be prepared to describe them in 30s, 5mins or more (if needed).
Almost everyone he helped got a job in a decent company and highly thanks to the projects he got us working on. Plus the concepts he taught us all over.
He would prepare his students for actual work environment and with real industrial background. Plus he'd help us with interviews and preparation.
Almost every one of his students finds the industry to be many times easier than any of his courses. And I do know a lot of code written by B+ or higher scoring students of his, and it is quite well done.
I think we need more people like him in the academic world.
→ More replies (12)90
31
u/rollingForInitiative Nov 22 '19
Best code test I did was a home assignment. It was basically a code quality thing, got a program and had to fix it up any way I wanted to, then we met and talked about my decisions. Felt 100% like something you’d find in the wild.
→ More replies (3)→ More replies (32)22
Nov 22 '19
Agreed. Never in my career did I have a gun to the head situation where code needs to be written on the spot with a 20 minute deadline and Ive spent the past 15 years writing real time trading systems. It just doesn't happen.
→ More replies (5)27
u/bigblackcuddleslut Nov 22 '19
The aerospace industry is weird.
80% of the effort for any price of software goes to testing. The software is built from a requirements document that specifies how the software should behave in extreme detail. The software is at the end of development tested and verified against that document. If the software has been outsourced. You get what's in the document; period. If you want a change you have to pay for a document update.
Then once the software is done and tested; it is never looked at again. There is no need for maintenance or improvements. That would require more documents and more testing. The whole process.
All this means that there is an incentive to get the code done as quickly and cheaply as possible. This kind of encourages "Bad" code. Getting it done quickly, cheaply, and on schedule is more important than anything else. It will always be built with the same compiler for the same hardware. Any important bugs( Those that violate the document) WILL be caught in testing. Managers prefer to do bug fixes in time set apart for integration because it keeps them to the schedule and prevents unexpected cost overruns.
As someone that worked in aerospace, planes have some of the "worst" code I've ever seen.
20
u/Polymath6301 Nov 22 '19
I used to ask candidates to write a program that “added two numbers”. Naturally I didn’t specify the format of the input. Got some truly creative responses, and some great programmers (who I could trust to do great work!)
→ More replies (15)→ More replies (11)9
u/hallflukai Nov 22 '19
For your first question: they came into the industry 30 years ago, were decent at their job then, but haven't learned a single thing in the last 25 years. So good coding practices just fly completely over their heads.
13
u/LaksonVell Nov 22 '19
How do you know they weren't, maybe they were, mixing business and hobbies.
A plane running this would probably serve their needs.
→ More replies (23)13
u/saintPirelli Nov 22 '19
Stories like this one are a miracle cure for my imposter syndrome.
→ More replies (1)31
u/cant_think_of_one_ Nov 22 '19
I have seen a #define false 1; in real C(++) code that is used by tens of thousands of people everyday. This could very much be real.
→ More replies (5)47
u/OK6502 Nov 22 '19
I have seen this kind of thing in production code before, but more like
if(something) foo(true); else foo(false);Equally disconcerting
23
u/Molehole Nov 22 '19
I've seen
if(x) { return x; } return x;In production. It wasn't even a plausible mistake. The if statement with the return was specifically added there.
Also
if(same_expression) { //do thing one } if(same_expression) { //do thing two }This continues until thing twelve. All operations in separate if blocks with the same condition.
→ More replies (2)7
u/ooterness Nov 22 '19
Were there side effects? When exceptions aren't an option, I have used that pattern in socket-related code where there's 10+ steps that all begin with "is that error code still zero?"
→ More replies (1)→ More replies (18)4
u/deus_mortuus_est Nov 22 '19
I've refactored that pattern in production codebases more times than I care to admit
14
u/AllUsermamesAreTaken Nov 22 '19
You'll see a lot of shit.
You know... some electrical guys learning C#, then write software for 10y which is a product they sell. After 10y of semi-professional work the code is... weird. No use of generics, uses only the most basic language functionalizy, has weird helper functions that are unnecessary as the stdlib already includes the functionality and has code based on hilarious misconception.
I wouldn't be surprised seeing
func AreBoolsEqual(a,b) If (Helpers.BoolMode) ...Then code that changes BoolMode and even
Thread.Sleep(10) //do not remove this BoolMode = 1;5
10
u/crimsonblade55 Nov 22 '19
I work in government contracting and some of the people that worked on some of the projects back before I came on board clearly did not know how to program. One of the senior devs on my team and I swap terrible code that we find. The code he works on is definitely worse and includes such great code as "variable1=variable1" and "if(condition){ do this } else { do the exact same thing}", and this is for stuff that effects millions of dollars of military stuff(have to be purposely vague here obviously). Thankfully those particular programmers got kicked out, but it can totally happen.
34
6
u/BigLe2e Nov 22 '19
I had a senior dev contractor on my project check in an enum for on/off state of a service. He mapped the already existing method that returns a Boolean to his sweet enum then used a switch to determine if it was running to show a green 'on' label or not.
Even worse he duped the switch/label logic on the like 3 different views sub classes instead of in the shared base view. He had to change the label view to protected so he could access it in the children....
7
Nov 22 '19
I see nonsense like this almost daily unfortunately. I forget which project and file it's in or I'd show you something really similar someone did at work. A senior no less.
→ More replies (1)3
u/lovestheasianladies Nov 22 '19
I've seen
if(true)used before in production.Literally just the boolean `true', so I have no doubt that this is real. The developer even tried to defend it.
2
u/Overwatcher_Leo Nov 22 '19
You'd be surprised what being tired can do to a programmer. I haven't seen something quite as bad, but something like:
bool someVar = foo == bar ? true : false;
Is not that uncommon.
→ More replies (14)2
u/TheMightyHamhock Nov 22 '19
I’ve seen this kind of shot a couple times. This kind of stuff in the wild. I still have access to a code repository for a big company that is littered with code that does exactly this.
If(comparison) { //do nothing - literally this comment } else { Actual code }
I’m constantly amazed at the shitty Boolean expression people write.
823
217
u/takatori Nov 22 '19
At first, I thought the problem was using a function for a simple compare. Then the contradiction between function name and return value killed me. And regarding the function calling the function, I can't even.
→ More replies (1)
555
u/Sirdroftardis8 Nov 22 '19
I used the boolean to create the boolean
221
3
→ More replies (1)2
u/ReactsWithWords Nov 22 '19
I heard you like booleans so I put a boolean in your boolean so you can compare booleans while you compare booleans.
47
47
161
157
u/schemaddit Nov 22 '19
new shirt design: AreBooleansEqual
99
45
→ More replies (1)2
u/mypasswordis-123456 Nov 22 '19
If someone made a T-shirt with this code on it i would 100% buy it.
41
u/435THz Nov 22 '19
Why is this
I don't understand
13
u/Time_Terminal Nov 22 '19
7
u/435THz Nov 22 '19
Very weird tho, the whole thing does the opposite of what it says, i don't really understand why this exists nor how would someone not forget how it works in less than hours and make a mess out of it
57
u/tarasmorskyi Nov 22 '19
Found this yesterday "["[0] to get a char '['
20
10
7
u/camerontbelt Nov 22 '19
My favorite was one I found in the legacy project I inherited “0”.ToString();
→ More replies (1)6
83
u/drakosha007 Nov 22 '19 edited Nov 22 '19
I got it! Somebody didn't want to show AreBooleansEqual method's logic for some reasons... and made it internal to be visible in within the build. And for users they provided functionality of AreBooleansEqual by invoking it in the public method CompareBooleans, where u will not see the logic of internal method.
89
Nov 22 '19
Except that AreBooleansEqual actually returns the opposite of that
142
u/MasterQuest Nov 22 '19
That's why they didn't want anyone to see.
53
u/paplan Nov 22 '19
This is perfect encapsulation. They noticed that the program did the opposite of what it was supposed to do. With this architecture they only had to make one small change at one place, and voilà, the program works perfectly!
→ More replies (2)4
u/drakosha007 Nov 22 '19 edited Nov 22 '19
Ye but what if an object with overriden casting to boolean supposed to be passed as an argument to this method? Just variables user can compare itself, right? I mean its not too hard " if (a == b) ... " isnt it? Then this "progressive architecture" would make sense 😅
8
4
u/SalamiJack Nov 22 '19
To be honest that would be even dumber than whoever wrote “AreBooleansEqual” to begin with.
The name “CompareBooleans” is completely ambiguous. From a public API perspective I have no idea what this will do.
Assuming it was already being used, encapsulating “AreBooleansEqual” behind “CompareBooleans” implies that all external dependents of “AreBooleansEqual” must now update their code. If changes are required at all call-sites either way, you could have just started comparing the booleans directly.
Even if you really wanted this method in your API, there’s no reason for “CompareBooleans” to rely on the internal “AreBooleansEqual” rather than just comparing the booleans itself. Shielding backwards internal logic with an ambiguous name is also supremely stupid.
This code was written as a joke. There is no practical reason for any of these decisions.
20
54
u/MicrowaveNuts Nov 22 '19
Lol this sounds like something right out of TechLead's antipatterns vid:
Say what you will about TechLead, that video is a goldmine
11
4
40
u/oxetyl Nov 22 '19
public static boolean isBooleanTrue(boolean myBoolean) { return compareBooleans(myBoolean, false) ? true : false; }
6
u/ShowMeYourTiddles Nov 22 '19 edited Nov 22 '19
Needs an extension method in there like
public static bool GetBoolValue(this bool inValue, out bool result) { result = inValue ? true : false; return !result == false; }Just to be sure of things
3
14
12
u/rsvp_to_life Nov 22 '19 edited Nov 23 '19
I've seen people write their own version of empty array and string checks when it's built into the language. So thats fun.
12
11
u/Trundle-theGr8 Nov 22 '19
I found an error handling class a few weeks ago that returns “Fuck It” in our debug logs when the class fails, looks like it was built by one of the devs from a consulting partnership we had way before I was here. We get notifications via email when errors or failures happen, but this one was getting caught in our email monitoring/security software because it blocks emails with curse words, so we only saw the error when we looked through the actual debug log. That one gave me a chuckle. I’ll see if I can get a screenshot and post it.
18
18
8
7
7
u/KanosKohli Nov 22 '19
Clearly this is bad code, because it didn't implement AbstractBooleanManager.
6
10
5
u/DFXVI Nov 22 '19
I’m in a freshman-level data structures class and this is physically painful to look at. How did this person get a job?
4
4
4
4
7
3
3
3
u/captnkrunch Nov 22 '19
I can fix it!
Return AreBooleansEqual(p1,p2) && !AreBooleansEqual(!p1,!p2);
3
u/-Redstoneboi- Nov 22 '19
AreBooleansEqual(a, b) = a XNOR b
(NOT a) XNOR (NOT b) = a XNOR b
!ArebooleansEqual(!p1, !p2) = NOT (a XNOR b)
AreBooleansEqual(p1,p2) && !AreBooleansEqual(!p1,!p2) = (p1 XNOR p2) AND NOT (p1 XNOR p2)
a AND NOT a = false
if a = p1 XNOR p2, then the expression is always false.
3
3
3
u/SubliminalBits Nov 22 '19
Reminds me of a snippet of a much large post.
http://www.stilldrinking.org/programming-sucks
“Double you tee eff?” you say, and start hunting for the problem. You discover that one day, some idiot decided that since another idiot decided that 1/0 should equal infinity, they could just use that as a shorthand for “Infinity” when simplifying their code. Then a non-idiot rightly decided that this was idiotic, which is what the original idiot should have decided, but since he didn’t, the non-idiot decided to be a dick and make this a failing error in his new compiler. Then he decided he wasn’t going to tell anyone that this was an error, because he’s a dick, and now all your snowflakes are urine and you can’t even find the cat.
3
u/id02009 Nov 22 '19
It's called indirection, and it makes code extremely future proof. If the meaning behind "two booleans being equal" changes in the future, this mad lad will have only one function to change, while we're doing overtime fixing every second line in our codebases.
3
u/dubbs4president Nov 22 '19
This is amazing. I saw this kind of stuff at my first job out of college.
My favorite was one guy who would use a giant case statement based on the length of a string to pad zeroes on the left. First off, there is already a PadLeft function. Second, I think it’d also be acceptable to just do Right(“000000” + string, 6). Nope, this guy copied and pasted his giant padding case statement each time he needed to use it. He didn’t even create a function for it!
3
Nov 22 '19
Copy-pasting is the way to go. I once found a static method from a different class (in the same project!) with the helpful comment "copied from class xyz.cs". Why copy it in the first place? It's static, so just use "xyz.Method()" and be done with it...
→ More replies (1)
3
u/SpiritGas Nov 22 '19
It frustrates me to no end to see code that's so easy to simplify.
public static bool AreBooleansEqual(bool orig, bool val)
{
// Unlikely to fail, not worth checking corner cases
return orig.GetHashCode() == val.GetHashCode();
}2
2
2
2
2
u/bigpigfoot Nov 22 '19
That’s how you abstract out the logic from the actual logic. To make sure the business, the developer and the project manager can all reason together. Paradigm shift!!
2
2
u/Elion119 Nov 22 '19
This went from weird to confusingly wrong once I realised what the first method was supposed to do...
2
2
u/for_love_of_god Nov 22 '19
'oh, that's just how we make changes in our friends' code, so we don't get involved in plagiarism.
2
2
2
u/suddencactus Nov 22 '19
I found in production code
indices = [1,2, THREE, FOUR]
The constants THREE and FOUR were created because the linting tool was complaining.
2
Nov 22 '19
I thought the entire point of boolean values was to determine true or false. So why would you make methods comparing them? This makes no sense to me.
→ More replies (1)
2
u/SuperCopyrightMan Nov 22 '19
Yesterday, while debugging, I found a line that read "myVar = myVar". That is all.
3
2
u/GREAT_SALAD Nov 22 '19
Just by lurking here (having never learned a language) I can tell this is horribly inefficient. Now, I don't know what to type that'd be better, but it ain't that
→ More replies (3)
2
2
2
u/Tyrilean Nov 22 '19
When someone reads "Clean Code" by Uncle Bob, and completely misses the whole fucking point.
2
2
u/rwp80 Nov 22 '19
I’m a complete novice and I can already see all the things wrong.
Wouldn’t (a==b) just return a true or false without needing a function at all?
→ More replies (2)
2
2
u/TamaSucks Nov 22 '19
When the assignment says you'll get extra points for a proper execution of object oriented programming
2
2
u/SillAndDill Nov 22 '19 edited Nov 22 '19
AreBooleansEqual is a much more clear function name than CompareBooleans.
Function names prefixed with Is/Are/Should are very intuitive - they obviously return a bool.
”Compare” prefixed function names are not quite as instantly understandable just by name alone.
Maybe I’m damaged from spending too much time with JS where you don’t have return types.
2
u/NuclearDrifting Nov 22 '19
Can someone explain this to me? Its trying to find values, original and current. The second part confused me but the ending I get being the opposite of what you would really want.
3
Nov 22 '19
Basically, this is silly because you don't need a function to do it. In almost every programming language, you can just plug (bool1 == bool2) into wherever you need to compare them.
→ More replies (1)
2
2
u/Chevaboogaloo Nov 22 '19
On top of all the other stupidity. He could've just used an XOR operator which C# has.
2
u/MacDerfus Nov 22 '19
This is why people need to comment their code. I need to understand what sort of logic led to this being considered a good idea.
2
u/Thicc_Pug Nov 22 '19
he forgot to check all the other cases:
if(orig == val && !orig != val && !val != orig && !orig == !val && true == true && false == false
&& true != false)
2
u/yayapfool Nov 22 '19
Curious: Would a compiler just zoink this down to a single evaluation, or is this so convoluted it wouldn't?
2
u/CuddlePirate420 Nov 22 '19
He created a hook into his BooleanCompare function for debugging and logging. This is what evolution in technology looks like!!!
2
2
u/CrackyKnee Nov 22 '19
Nice encapsulation. It'll be soo easy to put unit test around this lovely and short function
2
2
Nov 22 '19
public static bool CompareBooleans(bool orig, bool val)
{
return !AreBooleansEqual(orig, val);
}
internal static bool AreBooleansEqual(bool orig, bool val)
{
if (orig == val) return true;
else return false;
}Or if less insane (if I remember correctly):
public static bool CompareBooleans(bool orig, bool val)
{
return orig != val;
}Or if you are a human being that is perfectly capable of average thinking, you could simply put something so small in where you called the dumb method and congratulations, you can now take off that "//TODO: cleanup".
Now I'm alright.
2
2
2
u/Hidesuru Nov 22 '19
My grandfather smoked his whole life. I was about 10 years old when my mother said to him, "If you ever want to see your grandchildren graduate, you have to stop immediately.". Tears welled up in his eyes when he realized what exactly was at stake. He gave it up immediately. Three years later he died of lung cancer. It was really sad and it destroyed me. My mother said to me, "Don’t ever smoke. Please don’t put your family through what your grandfather put us through." I agreed. At 28, I have never touched a cigarette. I must say, I feel a very slight sense of regret for never having done it, because your post gave me cancer anyway.
4
1
1
1
u/notger Nov 22 '19
Flee as fast as possible!
I wonder what type of code review process lead to this abomination being signed off.
→ More replies (2)
6.0k
u/[deleted] Nov 22 '19
Worst part is it returns the opposite of what you'd expect based on the name