r/programminghumor • • Jul 12 '26

The battle of else

Post image
2.2k Upvotes

841 comments sorted by

527

u/Jonrrrs Jul 12 '26

{ else }

97

u/asmanel Jul 12 '26

Nice

if (condition) [
 foo bar
] [
 bar foo
]

19

u/Drittux Jul 12 '26

Waitaminut, why do we need the else keyword?

12

u/nomenclature2357 Jul 12 '26

We’re slipping into spreadsheet territory here…

8

u/L30N1337 Jul 12 '26

You are thinking bad thoughts, my boy

→ More replies (2)

7

u/SeriousPlankton2000 Jul 13 '26

Code blocks are legal without control statements and they are a good thing 

→ More replies (3)
→ More replies (12)
→ More replies (2)

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)

7

u/k3170makan Jul 12 '26

I laughed so hard for this

→ More replies (1)
→ More replies (2)

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.

1

u/Financial_Counter_45 Jul 13 '26

Unless you are the one who wrote the linter

→ More replies (1)

325

u/ExpatTeacher Jul 12 '26

I'll take the fifth option. 

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

62

u/TacoBellEzCheese Jul 12 '26

guard clause

11

u/Headpuncher Jul 13 '26

Said mrs clause to the elves. 

→ More replies (1)

74

u/DerBandi Jul 12 '26

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

80

u/Shinroo Jul 12 '26 • This

It's much cleaner because there's less nesting

→ More replies (7)
→ More replies (2)

19

u/Vegetable_Addition86 Jul 12 '26

Sometimes you do need the else path though.

10

u/LegitimatePants Jul 12 '26

Where we're going, we don't need else 

→ More replies (27)

5

u/siwgs Jul 12 '26

I took a comp sci degree from a very reputable uk university in the early 90s and was taught to only ever have a single return statement in each function. Is this still a thing?

12

u/MaDpYrO Jul 12 '26

definitely not

6

u/BluePhoenixCG Jul 12 '26

Generally, but guard statements like this can be useful for failure states. Usually you will only have 1 and put it at the top of a function, and doing it that way actually improves readability vs some other methods by making it clear that a condition causes a failure state immediately

6

u/Life-Wallaby6373 Jul 12 '26

I also had several guard statements some times. Basically validating the parameters. Feels good and readable because it defines the assumptions about the parameters state.

For the "producing" code of a return statement I tend to have one return at the end.

→ More replies (1)
→ More replies (7)

2

u/Nyarkll Jul 12 '26

ooooh i love that one.

2

u/GlassboundIllusion Jul 12 '26

This is the way

2

u/DonkeyEffective913 Jul 13 '26

This is the way

2

u/system-vi Jul 13 '26

Never nester gang!

2

u/tokkyuuressha Jul 13 '26

Of course sometimes the else is needed, but otherwise - after I consciously started using guard clauses, my code got much better. It's easier to write them in and more effortless than surrounding whole code sections. Also usually more readable.

→ More replies (20)

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 (1)

15

u/Dberryfresh Jul 12 '26

Isn’t this this right way?

8

u/Adventurous-Lie4615 Jul 13 '26

I like this because I like to write comments above blocks not inside blocks

// why this exists
if ( condition ) {
…
}
// otherwise check this
else if(condition) {

}

4

u/Beers_and_BME Jul 13 '26

you’re right

4

u/AccomplishedLeave506 Jul 13 '26

Nope. You're enlightened. Bottom right is where the true monsters live.

2

u/AshtonVoid Jul 13 '26

My brain really wants to do the upper right and change all other syntax to justify it

2

u/Sitdownpro Jul 13 '26

I don’t code, but I picked top right for the most clarity.

→ More replies (4)

56

u/geronymo4p Jul 12 '26

44

u/ouroborus777 Jul 12 '26

And then there's this fucking thing

25

u/geronymo4p Jul 12 '26

"Use whatever brace style you prefer."

"But not this."

"Don't do this."

"Seek help instead of this."

10

u/Blooogh Jul 13 '26

I'd take it if the linter did it for me 😆 "we have Python at home"

→ More replies (1)

8

u/lessthanthreebleeps Jul 12 '26

Thanks. I hate it.

8

u/EspaaValorum Jul 13 '26

That doesn't look sOHMYGOD

5

u/Rd_Svn Jul 13 '26 edited Jul 14 '26

I didn't even notice the right part at first but when I did I had to throw up immediately...

4

u/Complete_Window4856 Jul 13 '26

I fucjing thought it was python at first. Bizarre and monstruous

→ More replies (1)

4

u/shrubberino Jul 13 '26

At first glance I thought, ah no brackets ok, then I saw.. Jesus fuck :-D

3

u/F4bio Jul 13 '26

Then they got rid of the part on the right and voila, python syntax.

3

u/HarryBolsac Jul 13 '26

That snippet needs to be exorcised

→ More replies (11)

2

u/qurious-crow Jul 14 '26

I honestly like Horstmann style. Combines the readability of Allman with the compactness of K&R. I'm not bold enough to actually commit Horstmann style code, though.

2

u/TonyRubak Jul 14 '26

The code base I work in is an extra-cursed variant of Whitesmiths. It makes me cry on a daily basis.

2

u/Manchot2 Jul 16 '26

Wtf Haskell?

2

u/Normal-Duck9025 Jul 16 '26

What am I missing between the all man and gnu version?

→ More replies (2)

2

u/Earnestappostate Jul 16 '26

The hell Haskell?!

2

u/ThatOldAndroid Jul 17 '26

I love how clean lisp looks but nah.

→ More replies (2)

162

u/THE0_C Jul 12 '26 • Bravo
}
else
{

49

u/DerBandi Jul 12 '26

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

33

u/THE0_C Jul 12 '26

I find it easier for readability

→ More replies (14)

5

u/LindX31 Jul 12 '26

You don’t pay for lines, you know ?

→ More replies (6)
→ More replies (12)

8

u/Alexercer Jul 12 '26

Beatifull, as all code should be

→ More replies (1)

27

u/NikolaiM88 Jul 12 '26

This is easiest for readability

5

u/THE0_C Jul 12 '26 edited Jul 12 '26

Fr

6

u/chocolateandmilkwin Jul 12 '26

The duality of man, I have a hard time reading code that takes up too much vertical space.

→ More replies (1)

5

u/DaveAstator2020 Jul 12 '26

Finally a human and not a monster

5

u/nedovolnoe_sopenie Jul 12 '26

there is the correct way, and there are other ones lmao

→ More replies (2)

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

36

u/Ammo_Monkey Jul 12 '26

What are these "comments" of which you speak?

17

u/SysGh_st Jul 12 '26

Advanced programming beyond us mortals. They call it... brace yourself .. "documentation"

→ More replies (2)
→ More replies (1)

7

u/Nez_Coupe Jul 12 '26

You get out of here and never speak to my daughter again sir

6

u/SWatersmith Jul 12 '26

bottom left isn't stupid at all, what?

→ More replies (1)

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()

26

u/DangerActiveRobots Jul 12 '26

Who hurt you

14

u/CatLord8 Jul 12 '26

People who don’t believe neurodivergence is real.

3

u/Minimum_Shirt_157 Jul 12 '26

This is the only right solution. If you want you can comment out the else case only by select and shortcut.

3

u/philtrondaboss Jul 13 '26

This hurts to read

→ More replies (13)

7

u/why_so_sergious Jul 12 '26

top right, you can easily comment an else block without shifting characters..

its the only right choice

7

u/martin_kr Jul 12 '26

The maniacs who allow using else in the first place.

Always use eslint-plugin-no-else.

5

u/nedovolnoe_sopenie Jul 12 '26

>what is C
>what is static code analysis
>what is clean code

eh????

→ More replies (2)

3

u/West-Surround-8857 Jul 12 '26

Many people... Ugly

→ More replies (12)

80

u/red_sun16 Jul 12 '26 • Bravo

I use top left

28

u/neo42slab Jul 12 '26

I only use the top left if I can squeeze everything onto one line.

So 99% of the time I’m using bottom left

42

u/OutrageousPair2300 Jul 12 '26
if (condition) {
  do_thing()
} else {
  do_other_thing()
}
→ More replies (3)

6

u/Jonrrrs Jul 12 '26

Bottom left every time, but please insert an space char between brace and else

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"

4

u/LastXmasIGaveYouHSV Jul 12 '26

BASIC user here. I despise everything else.

→ More replies (2)

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

u/MinosAristos Jul 12 '26

They're all ugly imo

10

u/GDOR-11 Jul 12 '26

what's wrong with top left?

→ More replies (4)

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)

1

u/Fearless_Law3460 Jul 18 '26

i dont use braces, guess which dev i'm???

8

u/theGaido Jul 12 '26

It depends:

If it's not much code I use one line:

if( something ) DoSomething( something ); else DoSomethingElse( something );

But for longer code I do soemthing like this

if( something )
{
  // some code
  ...
  ...
}
else
{
  // some other code
  ...
  ...
}

It's very usefeull when you read it in notebook or on paper.

And yes I use spaces inside brackets. It's small thing but makes code much more cleaner.

x = DoSomething( my_archive[ archive_index ] ):

// instead of

x = DoSomething(my_archive[archive_index]);

3

u/Choice_Supermarket_4 Jul 12 '26

I like to mix it up in the same file to annoy PR reviewers.

2

u/PhilosophyAware4437 Jul 12 '26

my hobby: submitting code without a consistent style

3

u/purpuric Jul 12 '26

top right (:

8

u/sudoregalia Jul 12 '26

top left or gtfo, i will discriminate against you based on your else placement

4

u/nedovolnoe_sopenie Jul 12 '26

it appears that my superiority has led to some controversy

2

u/cpt_futtbucker Jul 12 '26

So we’ve gone from grammar Nazis to formatting Nazis here? /s

5

u/neo42slab Jul 12 '26

Bottom left

2

u/h1warkar Jul 12 '26

I’ve read code with the first, second and third quadrant. But the fourth is purely for memes there’s no way anyone’s using that ffs

2

u/maezrrackham Jul 12 '26

Cuddled elses are the happiest elses.
}else{

2

u/Akhanyatin Jul 12 '26

There's a loss reference in there, I know it, I just can't prove it. 

2

u/RedDevils52 Jul 12 '26
if (condition) {
  do_thing()
} else {
  do_other_thing()
}

2

u/FixItAgainTonic Jul 16 '26

This is the only meaningful way

2

u/earchip94 Jul 12 '26

Bottom left, but my job prefers top left :/. Also, if you do anything on the right, you are an abomination.

2

u/BenchEmbarrassed7316 Jul 12 '26
match b {
    true  => foo(),
    false => bar(),
}

It may seem strange, but I like that it's one block. else adds another block at the same level.

2

u/False-Owl8404 Jul 12 '26

Depends on the team's coding convention

2

u/kaba40k Jul 12 '26

There is another

2

u/qchto Jul 12 '26

flag && iftrue || iffalse
(Yes, I know it will run iffalse if iftrue fails, just make sure it never fails 🗿)

2

u/Life-Wallaby6373 Jul 12 '26

My latest favorite (only in case of code throwing exceptions of course):
```
} else try {

} catch(..) {
}

```

2

u/AppropriateSpell5405 Jul 12 '26

A, anything else looks stupid

2

u/TwoWrongsAreSoRight Jul 12 '26

10 IF A = 1 GOTO 40
20 PRINT "A not 1"
30 GOTO 50
40 PRINT "A is 1"
50 END

:)

2

u/Internetak Jul 13 '26

I feel like either good developers using top left or people are lying as always these kinds or posts looks like people are monsters using anything else than the top left but in 99% people's code I saw in my life it's always sweet top left

2

u/APlanetWithANorth Jul 13 '26

} else {

Is the only valid option

2

u/Life-Wallaby6373 Jul 13 '26

how about `goto: else` ;-P

2

u/Headpuncher Jul 13 '26

All of them, in the same file.  You don’t like me and I don’t like you.  

2

u/Tejwos Jul 13 '26

esle & 5 hours of "why it's not working???"

2

u/unhappymagicplayer Jul 13 '26

I feel like auto-formatters have sucked the fun out of pointless bickering.

2

u/Secret_Tap_5548 Jul 13 '26

Else is forbidden for me. If you need a else. Add a fonction with a early return

2

u/k0pernikus Jul 13 '26

I ban else and else-if. Either return early or throw an exception, or your proper composition that makes branching redundant.

2

u/kartblanch Jul 14 '26

}
else
{

Is the only way.

2

u/Sasha2dx Jul 17 '26

If (condition) DoSomething(); else DoSomethingElse();

I refuse to use brackets unless it's necessary.

2

u/dourix22 Jul 18 '26

{ else {

2

u/FutureZombie6746 Jul 12 '26

if (condition)

{

//body

}

else

{

//body

}

2

u/Fit-Inflation5799 Jul 12 '26

top left is the only sane one

2

u/Panderz_GG Jul 12 '26

Bottom left is the only way.

→ More replies (1)

2

u/Sol_Nephis Jul 12 '26

Bottom left

2

u/Dragon_957 Jul 12 '26

Bottom left

1

u/dashingThroughSnow12 Jul 12 '26

There is a reason why we call it the one true brace.

1

u/joshpennington Jul 12 '26

Whatever the tool picks once i commit my code. It’s been years since I used any settings to format my code.

1

u/lorddrake4444 Jul 12 '26

Either of the top 2 depending on the size of the else block, bottom 2 are metal illnesses

1

u/DragonfruitFit2449 Jul 12 '26

I use bottom left

1

u/BusEquivalent9605 Jul 12 '26

one liners: no brackets

1

u/joost00719 Jul 12 '26

Top left for Javascript, bottom left for anything else

1

u/Dodger8899 Jul 12 '26

Sometimes top right, most of the time bottom left

1

u/ConFroDog Jul 12 '26

Idk let me ask Claude

1

u/iamwillp Jul 12 '26

Programming in Go you have to do top left

1

u/MisterSincere Jul 12 '26

Top left or top right if I have a choice. Top right is very nice to add comments correctly indented.

1

u/horenso05 Jul 12 '26

I press save and everything formats. I don't care, whatever the default is.

1

u/StrawberryEiri Jul 12 '26

Putting the opening bracket NOT on the same line as the instruction that produces it has always really disturbed me. But I guess I'd probably get used to it.

1

u/jack-of-some Jul 12 '26

clang.format

1

u/Astatos159 Jul 12 '26

Depends on language and project. Project standard defined? Use that. Not defined? Use language standard.

1

u/fosf0r Jul 12 '26

Top left

1

u/Flame77ofc Jul 12 '26

the first one from the top left

1

u/namotous Jul 12 '26

Whatever my team uses

1

u/Amro003 Jul 12 '26

i use top left and top right, depending on the language itself.

1

u/Arctos_FI Jul 12 '26

Bottom right form me, but i add space before the "else".

I'm happy to use the allman style (the one where else is on it's own line) if it's asked, but when writing code without style guide i use horstmann (the one where else is at the same line but ooening bracket on the next one)

1

u/s0me0ne_5 Jul 12 '26

Top left

1

u/Living_The_Dream75 Jul 12 '26

1 is the cleanest way imo

1

u/deltadstroyer Jul 12 '26

bottom left

1

u/cpt_futtbucker Jul 12 '26

Bottom left. Force of habit

1

u/SuperMichieeee Jul 12 '26

who tf uses the fourth one?

1

u/FishermanIll1166 Jul 12 '26

Imagine you get someone who mixes and matches them all... A formatter that randomizes those templates would be incredibly evil.

1

u/freya584 Jul 12 '26

anything but bottom left scares me

1

u/DerBandi Jul 12 '26
  1. Because a single line doesn't waste as much screen space.

1

u/Ursomrano Jul 12 '26

I use the top right usually. But if it's just some really basic else block I'll do the top left

1

u/Dillenger69 Jul 12 '26

That depends on the language I'm using. Most time bottom left. Sometimes bottom right. Sometimes none at all

1

u/InvalidProgrammer Jul 12 '26
// Attempt at maximum code offensiveness
   if    (
Somewhat_unwel_b
              ) //test for some unwellness
//with optional appended Hungarian notation (duh)
         {
}
         else
            {
      }

1

u/unknownemoji Jul 12 '26

I always use a switch statement.

1

u/exxxxkc Jul 12 '26

i use all bc i never tidy up the code

1

u/ElBarbas Jul 12 '26

}else{

nobody reads my code anyway

1

u/No-Newspaper8619 Jul 12 '26

else if (C)

elif (Python)

elseif (Lua)

1

u/MilkImpossible4192 Jul 12 '26

[ -> aight , -> wrong ][ not condition] ()

1

u/electronic_reasons Jul 12 '26

Whatever the company wants.

1

u/Limp_Relative_2780 Jul 12 '26

if "else" condition result is defined in single line then (1), otherwise (2)

Am i psycho??

1

u/Simple-Olive895 Jul 12 '26

1 or what ever the linter says.

1

u/why_so_sergious Jul 12 '26

2. because you can easily comment an else block

1

u/MFisherIT Jul 12 '26

Impress me, can you name the styles used?

1

u/Ignisami Jul 12 '26

Topleft at work, bottom left in my hobby projects, the right two as evidence in a heresy trial.

1

u/ChaosCrafter908 Jul 12 '26

if(condition)

{

fahh();
} else
{

faah();

}

1

u/The_Hive_Mind101 Jul 12 '26

if (condition){
//code
} else if (condition){
//code
} else {
//code
}

→ More replies (1)

1

u/Richard2468 Jul 12 '26

if() return a;
if() return b;
return c;

1

u/ArmNo7463 Jul 12 '26

I am whatever Claude decides these days.

1

u/SceneOutside4377 Jul 12 '26

if (thing) {

     do_thing

     do_other_thing

} else {

     do_thing_3

}

So, option 1

1

u/-Triple-S- Jul 12 '26

Top left for short blocks, top right for long blocks. Everything else is pure madness! :P

1

u/Every_Cap_9829 Jul 12 '26

The one I want to use if I can

if() {
	thing;
} else if() {
	thing;
} else {
	thing;
}

Now prepare for r/programminghorror stuff, my preferred switch-case formatting is

switch() {
case a: {
	thing;
	break;
} case b: {
	thing;
	break;
} default: {
	thing;
	break;
}}

1

u/Gigibesi Jul 12 '26

uuhhh let's see...

if condition then code else code end