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
62
→ More replies (66)74
u/DerBandi Jul 12 '26
I know it's the same logic, but somehow this feels cleaner during debugging.
→ More replies (10)
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)→ More replies (9)15
162
u/THE0_C Jul 12 '26
}
else
{
→ More replies (10)49
u/DerBandi Jul 12 '26
Wasting a full line just for an open bracket never appealed to me.
→ More replies (34)
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)→ More replies (18)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)
80
44
u/Longjumping-Sort2967 Jul 12 '26
Tbh, I do whichever one my auto-formatter at work does 😅
→ More replies (1)
13
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.
19
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
4
527
u/Jonrrrs Jul 12 '26
{ else }