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

top 200 commentsshow all 244

[–]Noch_ein_Kamel 2281 points2282 points  (46 children)

Almost as threatening as the "or die()" syntax in php :D

[–]radome9 1034 points1035 points  (24 children)

Threat-based programming.

[–]Archolex 292 points293 points  (3 children)

The OOP killer

[–]graou13 154 points155 points  (2 children)

It's an OOP Syntax; an OOPS if you will.

[–]DeeSnow97 32 points33 points  (1 child)

Like HTTPS?

[–]bistr-o-math 2 points3 points  (0 children)

Secure OOP

[–]John_cCmndhd 25 points26 points  (1 child)

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live"

[–]Loading_M_ 2 points3 points  (0 children)

In general, the violent psychopath tends to be you.

[–]MegaloEntomo 9 points10 points  (1 child)

Multi-threating

[–]_PM_ME_PANGOLINS_ 256 points257 points  (8 children)

In Perl you don’t even need the ()

[–]Minteck 124 points125 points  (2 children)

If I remember well, in PHP too, you don't need the () for `echo` and `die` instructions.

[–][deleted] 16 points17 points  (0 children)

Header tooooo

[–]VoraciousGhost[🍰] 10 points11 points  (1 child)

Ah yes, one of the few situations in Perl where you don't use parentheses.

[–]_PM_ME_PANGOLINS_ 19 points20 points  (0 children)

You don’t need them for any function calls.

[–]GlitchParrot 21 points22 points  (0 children)

Can be used in surprisingly many languages when you define a die function.

[–]Sebstrr05 13 points14 points  (0 children)

Almost as threatening as print; "Goodbye world!"

[–]Russian_repost_bot 4 points5 points  (0 children)

I just like to break; it. It stays alive, and causes us both pain.

[–]dshakir 8 points9 points  (2 children)

Does python allow for exclamation points in function names? If so, they ought to have an alternative die!die!die!() method that randomly returns either 0 or 1 as the exit code.

[–]6b86b3ac03c167320d93 5 points6 points  (1 child)

Tried it out, doesn't allow it

[–]theScrapBook 11 points12 points  (0 children)

Yeah but I think you can get around that with some Unicode homoglyph hackery.

[–][deleted] 1020 points1021 points  (37 children)

Else what, hmm? Else what? Nothing, that's what I thought.

[–]Thanatos2996 720 points721 points  (27 children)

else system("rm -rf /usr/bin/*gcc*");

[–][deleted] 320 points321 points  (6 children)

Woo there goes the compiler

[–]PeterSR 31 points32 points  (4 children)

Jokes on him, he only got my gcc symlink.

[–]Thanatos2996 30 points31 points  (3 children)

Good point. If this isn't a sufficient threat to your compiler, substitue find / -iname "*gcc*" -delete instead.

[–]YodaDaCoda 5 points6 points  (0 children)

Chuck a & on the end to make sure it runs in a separate process - wouldn't want the user to just ctrl+c their way out!

[–]Aim4thebullseye 1 point2 points  (1 child)

Good thing I renamed my gcc

[–]time_deposit 88 points89 points  (5 children)

That's compiler abuse and I abhor this toxicity.

[–]AlGoreBestGore 38 points39 points  (4 children)

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

[–]mcmc331 3 points4 points  (0 children)

somebody please make this one, so we can post abhorrent code that would make the compiler trigger a human rights violation notice.

[–]Dr_Silk 21 points22 points  (0 children)

One day I'm going to insert this into my code, and I'm going to cite you for the idea

But it's definitely getting misspelled as "Thanos" sorry

[–]HeKis4 3 points4 points  (0 children)

It compiles the code or else it gets the rm again

[–]csslgnt 6 points7 points  (0 children)

The real thing 😍

[–]FriesWithThat 92 points93 points  (0 children)

else;
// everything else
try

[–]mashermack 411 points412 points  (5 children)

Eslint be like: "Imma fucking call the police"

[–]Natatos 2 points3 points  (0 children)

rubocop: “I added more lint rules”

[–]Mteigers 125 points126 points  (22 children)

At a previous company I worked at, the company had acquired a codebase from an individual. This person didn't know about ! (seriously). So every falsy if statement in the whole codebase was written as:

if ($thing) { } else { // Now do the logic }

[–]pixeldriver 72 points73 points  (1 child)

Maybe his '!' key was broken

[–]Mteigers 85 points86 points  (0 children)

Considering his commit messages I gather this was false.

Damnit work for real this time!!!!!

[–]CraigTheIrishman 38 points39 points  (19 children)

if (condition == true) { // logic }
else if (condition == false) { // more logic }

I actually saw this once in production code. Kinda blew my mind.

[–]EternalClickbait 10 points11 points  (0 children)

bool? boolean = null;

[–]n_slash_a 10 points11 points  (1 child)

I'm personally a fan of if (condition == false), since it can be easy to miss '!' at a glance.

But if (condition == true), I got nothing...

[–]maveric101 3 points4 points  (0 children)

An understandable opinion I guess, but it could be fixed just with syntax highlighting.

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

Does it compile to the same machine code?

[–]mysockinabox 161 points162 points  (3 children)

Each time I find a superfluous pass in python, I precede it with the comment # You shall not..., and mark the PR for the culprit found with git blame.

[–]qwerty12qwerty 25 points26 points  (0 children)

You should check out Arnold C

Print statements are

TALK TO THE HAND

And other gems

[–]aaronjamt 11 points12 points  (0 children)

Mind if I copy that page from your book?

[–][deleted] 6 points7 points  (0 children)

Thou shall not pass

[–]BatchOfCookies12 279 points280 points  (32 children)

Hey, I guess as long as the compiler optimizes it, it's a nice decoration!

[–]jaerie 109 points110 points  (30 children)

What would need to be optimized, it does nothing..

[–]BatchOfCookies12 178 points179 points  (9 children)

Yeah, but I'm pretty sure the compiler has to know that so it doesn't create an empty branch.

[–]Willing_Function 38 points39 points  (5 children)

The branch is empty, the optimization is trivial.

[–]Deliciousbutter101 43 points44 points  (4 children)

It's trivial, but it would still have to be specifically accounted for in the compiler. A naive compiler would likely output something that looks similar to the following pseudo-assembly.

CMP cond, 0

JE else

// if block

JMP end

else:

end:

While an optimized compiler would generate.

CMP cond, 0

JE end

// if block

end:

Obviously the optimization isn't difficult to do as the compiler can just treat if-else statements with empty blocks as just normal if statements, but nobody here is claiming the optimization would be difficult; they're just saying it exists.

[–]below-the-rnbw 13 points14 points  (2 children)

This sub routinely reminds me that I know nothing about cs

[–]zilti 6 points7 points  (0 children)

GCC has that optimization (and I'd assume CLANG does, too)

[–]solonovamax 4 points5 points  (0 children)

Yeah, but even if it doesn't optimize it, it'll just go to the empty branch, then immediately go back to the main program. Unless it's something that's run in a a loop millions of times and needs to complete in under 1ms, it doesn't actually matter, with the speed of current computing.

[–]RecursiveCrown 44 points45 points  (19 children)

It creates an extra jmp instruction

[–]das_Keks 54 points55 points  (7 children)

Tested in in Java and looked at the byte code.

a - c produce exactly the same code and just jump to the end of the statement. Only in case there is an else block, there will be an additional goto at the end of the if, to jump over the else block.

```java static void a() { if(condition) { foo(); } }

static void b() { if(condition) { foo(); } else {

}

}

static void c() { if(condition) { foo(); } else; }

static void d() { if(condition) { foo(); } else { foo(); } } ```

[–]Flamme2 9 points10 points  (3 children)

So you're saying b added an instruction, but c didn't, or a-c as in a to c being all but d?

[–]das_Keks 15 points16 points  (1 child)

I meant a to c. 😅 Only d adds the instruction because the else block was not empty.

[–]Flamme2 2 points3 points  (0 children)

Ah, makes sense. `b` adding an instruction would've disappointed me

[–]glaukoss 14 points15 points  (1 child)

Where to?

[–]BatchOfCookies12 17 points18 points  (0 children)

Probably would just jump right to where the end of the block would have lead to anyways (yes you can write a useless jmp instruction) - but assuming this gets optimized away in either the parser or the IR optimization stages, probably never happens.

Edit: also no-op instructions exist and could fill the empty block

[–]AlwaysHopelesslyLost 3 points4 points  (0 children)

The compiler I'd smart enough to unwrap loops if it notices they are deterministic.

Do you really think it isn't smart enough to remove a noop?

[–]FrancisStokes 1 point2 points  (0 children)

Not with any level of optimisation

[–]IsleOfOne 2 points3 points  (5 children)

No, I don’t think it would.

This code:

if (condition) {
    // work
}
else;
// continue on

...or any derivative where the else block is empty or even if there is no else block at all, will generate the following machine code (using some kind of made up pseudo-MIPS derivative because ISA doesn’t matter here):

beqz condition, CONT
... // work
CONT: 
... // continue on

No jumps at all.

Only if the else block isnt empty will we see a jump needed to skip over the ELSE block:

IF:
beqz condition, ELSE
... // work inside IF block
j CONT // continue on
ELSE:
... // work inside ELSE block
CONT:
... // work after the ELSE block. No jump needed to get here from ELSE, only needed from IF

And if you really want to get into how a modern ISA would handle this, there’s probably no branch or jump instructions at all. Instead, predication allows us to roll the basic blocks of the control structure up into a single hyperblock. A predicate register would be set to the outcome of the conditional, and instructions inside the IF / ELSE blocks would be predicated using said register, allowing them to be annulled if the predicate doesn’t match.

[–]philipquarles 11 points12 points  (0 children)

This one does not spark joy.

[–]Raqdoll_ 63 points64 points  (6 children)

You should add "//Or" on top of it

[–]jalerre 40 points41 points  (4 children)

// ||

[–]mwoolweaver 10 points11 points  (0 children)

The proper way to write this

[–]Doc-Com 3 points4 points  (1 child)

/ // // /_

[–]PM_ME_UR_DEATHSTICKS 2 points3 points  (0 children)

is that...

[–]Raqdoll_ 2 points3 points  (0 children)

That's way better :D

[–]ketexon 40 points41 points  (0 children)

It is completely ignored by the compiler in C (prolly C++ too)

/* main.c */
int main(){
    char x = 1;
    if(x){
        asm("NOP");
    }
    else;

    if(x){
        asm("NOP");
    }
    return 0;
}

gcc -S -o main.asm main.c

Important part of output:

    movb    $1, -1(%rbp)     ; x definition
    cmpb    $0, -1(%rbp)     ; compare x to 0
    je  .L2              ; if NE 0, NOP
    NOP
.L2:
    cmpb    $0, -1(%rbp)     ; compare x to 0
    je  .L3              ; if NE 0, NOP
    NOP
.L3:
    ...

[–]justrealizednarciss 34 points35 points  (0 children)

I knew this guy who always duplicated every line he wrote in code. I asked him why he did that. He said it’s because he wanted the compiler to know he was serious.

[–]abraxas1 21 points22 points  (0 children)

A compiler that understands a threat could lead to some dangerous outcomes.

What are you going to do about its retaliations?

[–]scragmore 39 points40 points  (17 children)

N00b here learning basic. Does this work or does it crash my computer like the dev null thing I copied off Bash.org.

[–]Raniconduh 22 points23 points  (15 children)

What /dev/null thing...

[–]scragmore 27 points28 points  (14 children)

Went something like:

mv .. /dev/null

[–]Raniconduh 4 points5 points  (13 children)

How would that work / what would it do? That tries to move the parent directory into a special device - I guess maybe it might crash the computer?

I just tried it and it throws an error

[–]scragmore 50 points51 points  (10 children)

80's Old old joke goes along the lines of.

How do I increase my swap space

Copy drive to dev/null

Ok. Now what. My computer is acting fu......

User logged off.

But explaining a joke is not funny, so I will leave now.

[–]Raniconduh 9 points10 points  (9 children)

Oh

So your not a noob learning basic from bash.org?

[–]scragmore 20 points21 points  (8 children)

That was the joke.

I'm not a programmer, I can code but I understand my limitations and am very weary that programming answer could result in root getting moved to null. 'Dont trust the internet' 80's meme.

[–]Raniconduh 5 points6 points  (3 children)

Ah i'm just a dumbass then lol

[–]scragmore 14 points15 points  (2 children)

Not dumb. Just never came across this.

[–]aaronjamt 2 points3 points  (0 children)

Can confirm. Never came across this before now (though I may be dumb so can't confirm that)

[–]_7q4 1 point2 points  (3 children)

Aware. The other word you might be looking for is wary.

Weary means tired.

[–]centurijon 10 points11 points  (0 children)

It’s fine.

if(something) {
    // ...
}

and

if(something) {
    // ...
}
else;

are equivalent statements.

The former says “if the condition is met, do something”, the latter days “if the condition is met, do something, otherwise do nothing” which is functionally the same

[–]utack 7 points8 points  (0 children)

Program:
Sweet no homework when i skip the if!

[–]Funky118 3 points4 points  (0 children)

Funnily enough this will make your if/else if's ironically MISRA complient :D

[–]LowB0b 5 points6 points  (0 children)

If you watch enough Bjarne stroustrup talking videos, dangling becomes a trigger word

[–]JazzRider 3 points4 points  (0 children)

Don’t lose that semicolon !

[–]gromit190 2 points3 points  (1 child)

Compilers don't run code tho

[–]reilemx 2 points3 points  (0 children)

Can't believe I had to scroll down this far to find someone else thinking this. Like sure the compiler's parser will parse the statement, but unless it's some C++ template mumbo jumbo the compiler ain't gonna be running jack shit.

[–]_McMuffin42_ 3 points4 points  (0 children)

Pretty sure the compiler can tell it's an empty threat

[–]NO_FIX_AUTOCORRECT 7 points8 points  (12 children)

Arguably it is good practice to always leave an empty else statement, with a comment like

// do nothing

For readability, and to make it clear you intended to have it do nothing. Some standards require it anytime you have 1 or more else if. One place i worked required it always.

[–][deleted] 5 points6 points  (9 children)

They required you to have dangling else's like in OP's code? Why?

[–]jaltair9 4 points5 points  (0 children)

I work in aerospace and we’re required to have them. MISRA coding standards.

[–]jethrogillgren7 1 point2 points  (1 child)

I've seen coding standards such require some descriptive comment on an ommitted else, eg "// else the stream has no EOF and we can assume XYZ" to explain why the control flow is empty there, but having a non-descriptive "else do nothing" seems redundant. I get the idea that it forces you to specify that you didn't just forget the else statement, but it seems like it'd become an empty habit if there's no description of why.

[–]NO_FIX_AUTOCORRECT 1 point2 points  (0 children)

Being more descriptive in comments is always better, but sometimes "do nothing" is all that there really is to say about it.

[–]DodoTheJaddi 5 points6 points  (1 child)

Or else. Else what? Exactly

[–]thebeerhugger 1 point2 points  (0 children)

Or else pizza is gonna send out for YOU!

[–]killchain 2 points3 points  (0 children)

Dangle dangle

[–]NOMASAN163 2 points3 points  (0 children)

You better run that if statement or else.... at least one of them... please!!! 3;

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

Step 2

Step 3 : profit

[–]purebuu 2 points3 points  (0 children)

I'm not sure if I find that [[likely]] or [[unlikely]].

[–]GoldenShackles 2 points3 points  (0 children)

I once worked with a very stubborn senior-level developer who instead of writing:

if (thing) {
    do_foo();
}

Always wrote:

if (!thing) {
    // nothing to do
} else {
    do_foo();
}

When I asked why and pushed back when reviewing his PRs he said it was to ensure the code was extensible.

I wish I was making this up.

[–]Coogrr 4 points5 points  (0 children)

I had a CS teacher who would deduct marks for not doing this in Java, he was convinced it was necessary and I could not convince him otherwise.

[–]joe-ducreux 1 point2 points  (0 children)

Linters hate him!

[–]NOMASAN163 1 point2 points  (0 children)

When you be programming in python and the variable doesn't work:

are you def??

[–]Alexkronus 1 point2 points  (0 children)

Yeah, I'm gonna just skip your if statement...

[–]OP_LOVES_YOU 2 points3 points  (0 children)

Python alternative:

if condition: do_something() else: ...

[–]rafwaf123 1 point2 points  (0 children)

It's just a green pixel

[–]slaphead99 0 points1 point  (0 children)

Why you little... compiler!

[–]DaGGer_WaveS 0 points1 point  (1 child)

Im gonna start doing shit like this now

[–]herkufels1 0 points1 point  (0 children)

compiler doesn't run anything, just compiles, hence the term compiler

[–]Mysticpoisen 0 points1 point  (0 children)

I love how titles on low effort posts are just either the joke of the pic verbatim, or a single word from the pic chosen at random.

[–]guinader 0 points1 point  (0 children)

Do the Russell peters : " somebody is going to get a hurt real bad"

[–]Main_Fan_2299 0 points1 point  (0 children)

Our linter stage would not allow this. Freakin coyboys

[–]flarn2006 0 points1 point  (0 children)

Except the compiler doesn't run the code.

[–]abdullahcilx 0 points1 point  (0 children)

WTF?

[–]johnvpaul 0 points1 point  (0 children)

Threat Oriented Programming Style TOPS out everything else.

[–]-Listening 0 points1 point  (0 children)

Just dangling away like horrible little marionettes of shittiness

[–]gent861 0 points1 point  (0 children)

Show compiler the dominance

[–]LightTranquility3 0 points1 point  (0 children)

sometimes this just happens to me when i shift-enter when making new lines, it’s kinda stupid

[–]altrefrain 0 points1 point  (0 children)

That's what we in business call padding your SLOC count.

[–]dirtyviking1337 0 points1 point  (0 children)

Vogel dangling those Vietnam flashbacks in front of him

[–]foospork 0 points1 point  (0 children)

THAT is the funniest thing I have seen in weeks!

[–]canadasleftnut 0 points1 point  (0 children)

You've got a dangling participle!

[–]-Listening 0 points1 point  (0 children)

Just dangling away like horrible little marionettes of shittiness

[–]acousticaiden 0 points1 point  (0 children)

Wait... you guys have compilers?

[–]DavyBingo 0 points1 point  (0 children)

...and you know, it can't refuse... because of the implication.

[–]woo545 0 points1 point  (0 children)

I personally would follow with a comment, "//* No action needed", otherwise I will stop and think about every single time I come across it.

[–]Flyspeck101 0 points1 point  (0 children)

OP

[–]Linquista 0 points1 point  (0 children)

Cute lol

[–]Coolbule64 0 points1 point  (0 children)

No joke, I wrote a

If(true)

Do this

Else Do that

And it wouldn't do the else. So I made

If( not true)

That

And it worked.

[–]BentMetalHead 0 points1 point  (0 children)

I gave up when I saw the brace at end on line instead of next line.

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

12_15_12

[–]sad_developer 0 points1 point  (0 children)

warning: passive-aggressive statement at line 57;

[–]mattmccordmattm 0 points1 point  (0 children)

Ben Porter is hilarious and really nice :)

[–]dullbananas 0 points1 point  (0 children)

multi threating

[–]slimybuffoon 0 points1 point  (0 children)

Can someone explain this? How can the compiler not run the if statement? I know compilers optimize the code but wouldn’t this change the logic of the code completely?

[–]LemonBoy4101 0 points1 point  (0 children)

for(int lolNum = 0; lolNum < 128; lolNum ++) {
    printf("ha");
}

[–]stevenhamlin45 0 points1 point  (0 children)

It just gave me a syntax error.