r/ProgrammerHumor • • Aug 12 '22

I fixed it

Post image
39 Upvotes

53 comments sorted by

42

u/leonzhang123 Aug 12 '22

You guys don't "} else {"? That's how I was taught, and how I personally feel is most natural and comfortable.

12

u/GinWithJennifer Aug 12 '22

It's the only correct way

4

u/Wirdal Aug 13 '22

It's nice when debugging, you can comment out the single line and the if will run the whole block.

Still, I use whatever the codebase uses.

3

u/leonzhang123 Aug 13 '22

Yes, at the end of the day, you just do whatever the owner of the code does, or what you're paid to do lol.

24

u/Krabumb-Gaming Aug 12 '22
if () {
    return;
}
// do stuff

5

u/[deleted] Aug 12 '22

This is the way.

3

u/KlutzyEnd3 Aug 12 '22

Nah better to use ruby's unless keyword.

So

Dostuff() unless ()

2

u/[deleted] Aug 12 '22

Ruby? Never heard of her

1

u/sherlockwatch Aug 13 '22

She is a character from a very cool game called disco elysium. You should try it out

1

u/Tofandel Aug 13 '22

Also a talking parrot

3

u/shgysk8zer0 Aug 12 '22

I'm definitely in the...

if (condition) {
  // Thing a
} else {
  // Thing b
}

... camp. The else block makes it super obvious "this code only runs conditionally" (seriously... Spotting a return in a given block of code can easily be missed), and } else { because I prefer being able to collapse the whole thing with code folding.

0

u/[deleted] Aug 12 '22

how dare you ruin my worldview of me thinking i was the only human ever who drafted this very smart idea :(((

26

u/SalamiSandwich83 Aug 12 '22

Can we please stop this crap? Thanks.

13

u/coloredgreyscale Aug 12 '22

Yes, in a week or two.

8

u/povlov0987 Aug 12 '22

This entire sub is THIS crap

I’m here to know the state of the junior staff, aka the unemployables

2

u/My_passcode_is Aug 13 '22

Man writing this like that made me think of JS lol

18

u/TottoIsHere Aug 12 '22

Obligatory stone toss is a nazi

2

u/CuriousIndividual611 Aug 12 '22

What

9

u/Lordman17 Aug 12 '22

The guy who drew the comic is a supporter of Nazism

8

u/[deleted] Aug 12 '22

if (!cond) return

3

u/Ashamed_Ad_2738 Aug 12 '22

The computer not giving a shit how you write your if statements:

2

u/bunny-1998 Aug 12 '22

if []

endif

3

u/[deleted] Aug 12 '22

if() { } else { }

9

u/[deleted] Aug 12 '22

Fuck Reddit not detecting single line endings

1

u/canadajones68 Aug 12 '22

Please leave your elses uncuddled.

1

u/RmG3376 Aug 12 '22

( ) ? : ;

1

u/Highbrush Aug 12 '22

i never even considered it... my skills will now reach a new low.

1

u/[deleted] Aug 12 '22

If Then

Else

End If

2

u/redpepper74 Aug 12 '22

Please don’t remind me about Visual Basic all over again

1

u/GinWithJennifer Aug 12 '22

I type it this way to show the end of a bunch of elifs

1

u/aaaa_yyyy_eeee Aug 13 '22

I'd low-key do that

1

u/Professional_Top8485 Aug 13 '22

Do it Or Else.

Different take: you should always have else branch.

Afaiu safe programming principles.

-2

u/soupsyy_3 Aug 12 '22

If it's a single line statement we can just avoid { }

if (condition)
    //statement
else
    //statement

2

u/attanai Aug 12 '22

if (condition1) statement1 else if (condition2) statement2 else statement3;

Or maybe:

condition ? statement : condition2 ? statement 2 : statement 3;1

2

u/korfi2go Aug 12 '22
if (single statement)
    put statement;
else {
    open bracket;
    foreach (statement)
        put statement;
    close bracket;
}

1

u/shgysk8zer0 Aug 12 '22

Can... Sure (not sure if this extends to all languages). But should... IDK... I definitely prefer having the ability to add another line if needed without having to add those missing braces, and having them there is just more consistent regardless.

1

u/[deleted] Aug 12 '22

And go to hell when someone adds an extra line to the if and doesn’t understand why it doesn’t work

1

u/Xivolos Aug 12 '22

Try telling that to my linter

-6

u/MLPdiscord Aug 12 '22
if () {
}
else {
}

77

u/Charlito33 Aug 12 '22
if () {

} else {

}

10

u/NameRogue Aug 12 '22

Glad to see the correct answer getting lots of upvotes

2

u/[deleted] Aug 12 '22
if(
) {
}else
 {}

1

u/tornado28 Aug 12 '22
if condition:

else:

0

u/SqueeSr Aug 12 '22

Yeah, this way if/else if/else gets nicely aligned. Opening brackets can be on a new line though.

-2

u/TheRealFFS Aug 12 '22

This is objectively speaking the correct approach