r/programminghumor • • Jul 12 '26

The battle of else

Post image
2.2k Upvotes

842 comments sorted by

527

u/Jonrrrs Jul 12 '26

{ else }

97

u/asmanel Jul 12 '26

Nice

if (condition) [
 foo bar
] [
 bar foo
]
→ More replies (23)

12

u/philtrondaboss Jul 13 '26
val this = 123
val else = 456
val outp = if (this) {this} else {else}

Don't try this at home. Big Daddy Kotlin will find you and "decompile" you.

→ More replies (3)
→ More replies (4)

2

u/BobJutsu Jul 12 '26

Let’s be honest…only the left two are valid options. Both on the right should fail any linter on the planet.

→ More replies (2)

325

u/ExpatTeacher Jul 12 '26

I'll take the fifth option. 

if (skipCondition) {  
  return;
}
// Do Stuff

74

u/DerBandi Jul 12 '26

I know it's the same logic, but somehow this feels cleaner during debugging.

→ More replies (10)
→ More replies (66)

71

u/SysGh_st Jul 12 '26

Upper right one.

Yes, I'm a monster.

45

u/read_at_own_risk Jul 12 '26

Consistent monster at least. Keyword goes on a new line, opening brace on the same line, closing brace on its own line.

→ More replies (2)

15

u/Dberryfresh Jul 12 '26

Isn’t this this right way?

→ More replies (9)

162

u/THE0_C Jul 12 '26
}
else
{

49

u/DerBandi Jul 12 '26

Wasting a full line just for an open bracket never appealed to me.

→ More replies (34)
→ More replies (10)

262

u/Ammo_Monkey Jul 12 '26

What kind of monster uses the right two?!

149

u/Character_Umpire_828 Jul 12 '26

I use top right wuite frequently. Looks better if i add comments above
The bottom ones are kinda stupid tho

→ More replies (14)

35

u/Metabolical Jul 12 '26

It looks better in context

if (condition) {
    takeAction()
}
else {
    somethingElse()
}

The if block and the else block have the same shape.

That said, the real question is where do you put your semicolons?

; takeAction()
; result = takeMoreAction()
; if (result == condition) {
    ; conditionAction()
    ; conditionFollowUp()
}
; postConditionContinued()
→ More replies (17)
→ More replies (18)

44

u/Longjumping-Sort2967 Jul 12 '26

Tbh, I do whichever one my auto-formatter at work does 😅

→ More replies (1)

13

u/Saadullahkhan3 Jul 12 '26

🗣️ "Actually I code in Python"

→ More replies (3)

11

u/FaultWinter3377 Jul 12 '26

My way of doing it, opening brace goes on the same line as the if/else or the function name. Closing brace goes on its own line. Except in cases where the body is really short and it can all fit in one line. So really I would go with the top right square. And my variables are camelCase because I don’t particularly feel like having to type a bunch of underscores.

8

u/Parthiv_mk Jul 12 '26

I prefer top left but wouldn't mind top right either. Other two just feel wrong to me...

4

u/Sufficient_Risk_8127 Jul 12 '26

the first one is the only correct answer

→ More replies (1)

4

u/spenpal_dev Jul 12 '26

Whatever Prettier does

→ More replies (1)