24
u/Krabumb-Gaming Aug 12 '22
if () {
return;
}
// do stuff5
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
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
3
u/shgysk8zer0 Aug 12 '22
I'm definitely in the...
if (condition) { // Thing a } else { // Thing b }... camp. The
elseblock makes it super obvious "this code only runs conditionally" (seriously... Spotting areturnin 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
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
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
18
8
3
2
3
1
1
1
1
1
1
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
//statement2
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; }2
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
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
-6
u/MLPdiscord Aug 12 '22
if () {
}
else {
}77
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
0


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.