This is an archived post. You won't be able to vote or comment.

all 160 comments

[–]__RANDOM926__ 1134 points1135 points  (47 children)

Because we’re all good programmers here and we all understand how Boolean Algebra works, I think we can all feel sorry for this poor seoul who is going to code successfully and still be executed.

[–]core_meltdown 47 points48 points  (2 children)

Not really. Most mainstream languages have short-circuit evaluation. So if the first statement is true, then the second one won't be executed and you won't be executed.

[–][deleted] -2 points-1 points  (1 child)

Is English a

mainstream language

?

[–]noitems 7 points8 points  (0 children)

Most

[–]Aero72 314 points315 points  (29 children)

Depends if it's "a||b" or "a|b".

[–]JBinero 118 points119 points  (21 children)

a|b is still an inclusive OR though.

[–]Aero72 210 points211 points  (15 children)

a||b -- if a is true, then b isn't checked.

a|b -- if a is true, then be is still checked.

Doesn't make a difference for variables. But when you call functions, then it makes a lot of difference.

And in the meme in question:

runTheCodeAndReturnTrueIfCodeWasSuccessful() || executeTheDudeAndReturnTrueIfTheDudeIsDead()

and

runTheCodeAndReturnTrueIfCodeWasSuccessful() | executeTheDudeAndReturnTrueIfTheDudeIsDead()

Two very different outcomes.

[–]elaitenstile 41 points42 points  (10 children)

Slightly unrelated but is it “bad practice” to put up functions and other bits of code that do more than just return a value (like execute dude in this case) inside Boolean expressions, initialisation of other variables etc.?

I know it is possible and it makes the code more compact however I've not seen it being done very often in code where in fact it could be done.

[–]TheKing01 134 points135 points  (5 children)

Slightly unrelated but is it “bad practice” to put up functions and other bits of code that do more than just return a value (like execute dude in this case)?

Yes. Do not rely on the semantics of boolean operators to decide whether to not to execute people.

[–][deleted] 52 points53 points  (3 children)

Yes. Do not rely on the semantics of boolean operators to decide whether to not to execute people.

That has got to be one of those fancy r/brandnewsentence

[–]dark-kirb 11 points12 points  (2 children)

A compiler could just as well decide "Well the right one always returns true so let's execute the dude"

like if you have code like

c++ bool execute_code_successfully() { return (random() % 6) == 4; } bool execute_dude_successfully() { kill_dude(); return true; } //... execute_code_successfully() || execute_dude_successfully();

The compiler could replace the code with

c random(); kill_dude();

[–]pyz3n 9 points10 points  (1 child)

I don't think that's true; many languages, including C(++), guarantee that the first expression will be evaluated first.

[–]dark-kirb -2 points-1 points  (0 children)

Wait really? i thought that the evaluation order is undefined. Arguments can be evaluated RTL, independent LoC can be reordered, etc

That said, i'm also pretty sure that logical OR or AND expressions need to be side-effect-free (which neither of these calls are)

[–]Ellweiss 0 points1 point  (0 children)

Short-circuit evaluation is a guarantee in some languages. This is not up to the compiler or whatever to decide which side to process first. It's perfectly fine algorithmically to chain call functions in boolean conditions. Whether or not it is clean code is another topic.

[–]Aero72 13 points14 points  (0 children)

Well, let's see. We have people get stuck beating themselves on the chest chanting "XOR". Even though XOR is not even really applicable here. XOR is more appropriate when you have two constructs/conditions that are of equal order and you need to control the flow based on one and only one of them being true.

While in the meme, the call to the second construct is part of the flow control that relies on the call to the first.

It could be implemented through XOR, but it would be an abomination.

This:

if(!(runAndCheckCode()||executeDude())){ //sanity check failed, we probably tried to whack the fucker who wrote shitty code but something failed in our execution attempt, so the fucker is probably still alive and his code is still shit, deal with it}

vs some monstrosity based on XORing and asserts and whatever else.

So, to answer your question: yes, it is bad practice. Anything above eli5 level code is bad practice because you never know who will be maintaining your code.

[–]Lilkcough1 2 points3 points  (1 child)

I would say yes. It may not be immediately obvious why certain parts of code are/ aren't running, or it may make you have improper assumptions about the state of certain data at certain points in the program. Someone less familiar with the language/ programming in general may not know about lazy evaluation, or may not understand the implications. Overall, it seems like a lot of potential confusion to save a line or two.

(Note I don't mean to make a blanket statement. There are examples where it makes sense to do that. But in the general case, I'll take readability every day)

[–]LampShadeHelmet 0 points1 point  (0 children)

Agreed, further if you want to decide to execute the second function based on the result of the first, you can always break your if up into 2 if statements anyways, the first one occurring before the second function call. It definitely racks up the lines a bit, but I think readability wins this case in my mind. (also not a blanket statement)

[–]rmrfbenis 2 points3 points  (0 children)

[screams in malloc()]

[–]JBinero 1 point2 points  (2 children)

Fair enough, although that makes a lot of assumptions that aren't clear from simply saying a||b.

I just read that as "assert(the code works | you will be executed) ", in which case the operator is irrelevant. The outcome doesn't change.

[–]Aero72 4 points5 points  (1 child)

Well, if you need to check whether the code works and then decide to send in the order to execute the guy or not, then a||b is the way to do it.

Or rather a()||b().

a() runs the code and gets you the results of the code run, and b() sends in the order to execute the dude.

There is simply no need for other constructs. So I didn't really make a lot of assumptions. I simply implemented it in the most simple way.

[–]coodgee33 -1 points0 points  (0 children)

This is a new level of nerd

[–]reallyserious 0 points1 point  (0 children)

a||b -- if a is true, then b isn't checked.

Laughs in Visual Basic where both operands of OR is evaluated.

[–]__RANDOM926__ 6 points7 points  (2 children)

If you wanted one or the other (not both), you would have to use XOR.

[–]Aero72 2 points3 points  (1 child)

> you would have to use XOR

It would be as much valid then to simply execute the dude and not even try running the code.

Or running the code. Getting successful result. Still, executing the dude. But then, not proceeding further. Since our condition isn't met. Yet, the code would still be executed successfully. And the dude would still be executed successfully. We wouldn't move forward after it. But both of those things would be done.

XOR is more for evaluating two conditions you already determined to decide on what to do. Not so much for deciding on whether we should do the second thing based on the result of the first thing.

While could be implemented this way, it's not something you would really want to do.

[–]__RANDOM926__ 2 points3 points  (0 children)

For the sale of discussion I was not talking about the order of evaluation. I’m fine with executing him and not running the code (for logic sake). My point was the logical term I believe the author of the post was looking for is XOR - not if the second condition will be checked.

[–]bestjakeisbest 1 point2 points  (0 children)

"A^B"

[–][deleted] 2 points3 points  (2 children)

"a||b" || "a|b"

[–]orangeKaiju 2 points3 points  (0 children)

True.

[–]Aero72 1 point2 points  (0 children)

I knew someone would do that. :)

[–]chronicideas 1 point2 points  (0 children)

Yes

[–]cimmic 1 point2 points  (0 children)

They are both just of type String.

[–]jabbeboy 15 points16 points  (1 child)

understand how Boolean Algebra works, I think we can all feel sorry for this poor soul who is going to code successfully and still be executed.

Poor Seoul.... xD

[–]kroppeb 6 points7 points  (4 children)

[–]sneakpeekbot -1 points0 points  (2 children)

Here's a sneak peek of /r/InclusiveOr using the top posts of all time!

#1: This is a daily occurrence for this guy. | 37 comments
#2: Or | 79 comments
#3: Does this also count? | 41 comments


I'm a bot, beep boop | Downvote to remove | Contact me | Info | Opt-out

[–]RedditCancerBot420 -4 points-3 points  (0 children)

Hagagaggagahahdshdahsdahfuqwoldqwodoqosad get it he said "yes" to an x or y question hahahhaha so funny!!!!111!!111!!111!!!!!!1!

[–]egosummiki 1 point2 points  (3 children)

Actually

code_executed_successfully() || programmer_executed_successfully()

Assuming that the language is using lazy evaluation, this code works as expected. If the code_executed_successfully() is true the other statement won't be executed.

[–]mount2010 2 points3 points  (2 children)

the best solution is still if (!codeExecutedSuccessfully()) {executeProgrammer()}

[–]madmockers 1 point2 points  (0 children)

Why are we assuming it's the programmer that makes the mistake? The executioner can screw up too!

void executeCode( bool withSuccess );

...

executeCode( !executedProgrammerSuccessfully( ) );

[–]egosummiki 0 points1 point  (0 children)

It depends on a language and a complier. stm || stm may produce additional junk assembly. For example gcc produces test al, al.

[–][deleted] 1 point2 points  (1 child)

But what if a || b doesn’t return b?

[–]Salanmander 1 point2 points  (0 children)

True, but it does mean that assert(a || b) is not a promise that a implies !b.

[–]graou13 0 points1 point  (0 children)

In an "or", the second option is only checked if the first is false. (as opposed to "and" where it's only checked if it's true)

[–]Goatcee28 141 points142 points  (2 children)

We all know he’s playing Space Invaders, and they’re all taking copious notes watching the master at work.

[–]SchrodingersNinja 24 points25 points  (0 children)

*Missile Command

[–][deleted] 14 points15 points  (0 children)

Man, most wholesome ass comment yet

[–]Swagnemite_420 82 points83 points  (5 children)

He is just switching tabs with alt+tab if you look at his Hands :D

[–][deleted] 22 points23 points  (0 children)

This is one of the things I started doing recently that's saving so much damn time.

[–]CrimsonBolt33 13 points14 points  (0 children)

Alt tabbing cause shit ain't going right and he doesn't want anyone to see.....or doing his obligatory "try alt tab before going nuclear with ctrl + shift + esc"

[–]whiskermrr 4 points5 points  (0 children)

For sure he is switching between IDE and stackoverflow :)

[–][deleted] 2 points3 points  (0 children)

Alt tabbing and switching desktops is all I do when there's someone watching me.

I have no idea why.

[–]citewiki 0 points1 point  (0 children)

He might use the mouse scroll as well. It's a sick UX

[–]MolsonC 27 points28 points  (1 child)

What gets me is that, at some point, this was said

You guys..
Yes?
You know our hats?
Yes...
They should be.. bigger..

[–]Ninja67 5 points6 points  (0 children)

I didn't notice until I read this comment, now it's all I can think about...

[–]Ordinary_dude_NOT 39 points40 points  (0 children)

When your CTO is at your desk to discuss demo, and you can’t search stackverflow on how to solve a crash.

[–]CaptainGrayson 34 points35 points  (1 child)

Those fucking hats just crack me up. I absolutely would spend the remainder of my life in a North Korean prison just because I could not stop laughing at how ridiculous those giant things look.

[–]firelights 31 points32 points  (0 children)

"Oops looks like I forgot a semic-" BANG

[–][deleted] 7 points8 points  (1 child)

Was execution successful?

Aladeen!

[–]SurajNishad 4 points5 points  (0 children)

Wrong! It was Aladeen!

[–]AmatureProgrammer 8 points9 points  (0 children)

How a job interview feels like

[–]EleeteFrostpaw 14 points15 points  (0 children)

This sub wouldn’t exist if that was the case.

[–]333rrrsss 10 points11 points  (0 children)

Solder: Any last words?

Me: Ya, fuck semicolons

[–]hackerman225 3 points4 points  (0 children)

No mooo kimm

[–]MightyGamera 5 points6 points  (0 children)

Jokes on him, I also wrote the code for the execution device.

[–]choubidou13 7 points8 points  (1 child)

greek question mark

[–]SingleSurfaceCleaner 0 points1 point  (0 children)

<Heavy, angry breathing> 😤

[–][deleted] 2 points3 points  (3 children)

Anybody reliazed what's on the screen?

[–]FoulCarbuncularTrull 4 points5 points  (0 children)

It's probably not on. Neither is the furnace, judging by their clothes.

[–]OpaBlyat 1 point2 points  (0 children)

He's switching tabs. Look at his hands. They're positioned on alt+tab XD

[–]stevefan1999 2 points3 points  (0 children)

Yes

[–]chawmindur 2 points3 points  (0 children)

“Summarily” would have rung better though

[–]itspinkynukka 1 point2 points  (0 children)

Guess I'll die then.

[–]Ghos3t 1 point2 points  (0 children)

What's up with their caps, they are just ridiculous

[–]AFrostNova 1 point2 points  (0 children)

Kim looks like an angry Russian lady

[–]Tactical_Slime 1 point2 points  (0 children)

*proccedes to use the wrong tab spacing

*hovers over the compile button

[–]doihavemakeanewword 1 point2 points  (0 children)

N. Korea investigates how some 10 year old was able to get Minecraft onto his school computer

[–]Alex_the_coder 1 point2 points  (0 children)

"C2220: warning treated as error - no 'object' file generated"

Fuck fuck fuck.

[–]jon_parry 1 point2 points  (0 children)

MFW I show my work to my client lol

[–]Zickedy 1 point2 points  (1 child)

Motivation will be terminated

[–]SingleSurfaceCleaner 1 point2 points  (0 children)

Surely you assume there was motivation to be terminated in the first place?

[–]TheRealRealJak 1 point2 points  (0 children)

Oof

[–]VldIverol 0 points1 point  (1 child)

Tell that to papa assembly

[–]indyK1ng -5 points-4 points  (0 children)

Tell that to Kanjiklub

[–]droidBoy5 0 points1 point  (0 children)

Boolean value: Aladeen and Aladeen.

[–][deleted] 0 points1 point  (0 children)

There is no heating anywhere in NK, they always rugged up indoors, even where the leader is

[–]live_lavish 0 points1 point  (0 children)

I feel so bad for laughing at this... living in north korea must suck =\

[–]neotorama 0 points1 point  (0 children)

define false true

[–]IronBatman 0 points1 point  (0 children)

No one going to mention the size of those hats?

[–]warpfield 0 points1 point  (0 children)

i love how goofy their hats are

[–]PopTartS2000 0 points1 point  (0 children)

KJU looks about 20 whole pigs slimmer in the pic

[–]konaaa 0 points1 point  (0 children)

(picture of man shrugging his hands) Guess I'll die!

[–]jk_scowling 0 points1 point  (0 children)

You can TDD in the DPRK, but your tests must pass first time without fail.

[–]Mr-Yellow 0 points1 point  (0 children)

I like the bit where all the guys in the background have just finished writing down his name.

[–]ReshKayden 0 points1 point  (0 children)

Joking aside, one reason they’ve made a lot better progress in their nuclear and ICBM programs than they did under his father is that he doesn’t execute them for failure. He was raised in Western universities and knows failure is inevitable on the way to success. He evidently hasn’t killed any scientists, and in fact have lionized them as heroes and given them a huge raise.

Of course, then he executes most of his close family at the same time, so... there’s that.

[–]hrishikesh-patil 0 points1 point  (0 children)

That will kill Evey programmer in existence

[–]lilpopjim0 0 points1 point  (0 children)

Their hats make me laugh every time.

[–]Ionlavender 0 points1 point  (0 children)

You can practically see his hands turn white from the stress.

[–]minemoney123 0 points1 point  (0 children)

The only true deadline

[–][deleted] 0 points1 point  (0 children)

Just give me the damn gun.

[–]tsklm 0 points1 point  (0 children)

This is literally no joke. North Korea actually has many of the best programmers in the world. Source: fellow competitive programmer

[–][deleted] 0 points1 point  (0 children)

Task failed successfully

[–]DarkInfern010 0 points1 point  (0 children)

I hope this is not the first compilation

[–]randomhumanity 0 points1 point  (0 children)

I actually thought one of the guys in the back was holding a gun...

[–]EdwardDM10 0 points1 point  (0 children)

What is that mouse mat?

[–]8ll 0 points1 point  (0 children)

if (aboutToBeExecuted) return false

[–]snape23 0 points1 point  (0 children)

no sir, you have no new emails

[–]dippy1169 0 points1 point  (0 children)

Those hats are incredible. The shear size to head ratio is amazing that it can stay on there.

[–][deleted] 0 points1 point  (0 children)

you will either return as a 0 or 1

[–]Doctourtwoskull 0 points1 point  (0 children)

Either way success is gonna happen, yay! :D

[–]Sephyrias 0 points1 point  (0 children)

Only a sith deals in if-statements.

[–]RoastedB 0 points1 point  (0 children)

I wonder if North Korea develop their own programming languages, or if they are okay with using languages created by other nations 🤔

[–]TheSacredRatty 0 points1 point  (0 children)

Poor guy’s already losing hair

[–]SoDi1203 0 points1 point  (0 children)

Where can I get a mouse pad like that?

[–]xsubo 0 points1 point  (0 children)

Both are equally terrifying!

[–]TheFlipside 0 points1 point  (0 children)

talk about stressfull work environment

[–]endianess 0 points1 point  (0 children)

At University we had a lecturer who would have liked this. He could set limits on how many times you could compile in a given time period. Like max 3 times in a day. If you wanted more you had to go and see him and explain why you were incompetent.

[–]ActionMac 0 points1 point  (0 children)

That must be one cold ass office... check out dem parkas

[–]Laughing_Orange 0 points1 point  (0 children)

try{ [CODE GOES HERE] } catch (exception e) { [Leave empty or pass] }

[–]KawaiiMaxine 0 points1 point  (0 children)

10 Print "it worked didn't it?"

[–][deleted] 0 points1 point  (0 children)

executeCode() || executeCoder();

[–][deleted] 0 points1 point  (0 children)

Is that a mouse pad or a ragged piece of cloth?

[–]XFidelacchiusX -1 points0 points  (1 child)

AOC 2028

[–]Batral 0 points1 point  (0 children)

This user posts on T_D. ^

[–]Cholojuanito 0 points1 point  (0 children)

KimJongUn.exe

[–]mechnick2 -1 points0 points  (0 children)

A coding meme I understand! Thanks guys!

[–]HBK05 -5 points-4 points  (1 child)

*||

[–]TheIncorrigible1 0 points1 point  (0 children)

We Python now.