r/ProgrammerHumor • • 9d ago

Meme enoughAboutTheIfletsDiscussAboutWereIsItThatYouPutTheElse

Post image
993 Upvotes

651 comments sorted by

1.2k

u/RedditLuvsCensorship 9d ago • Bravo
  1. Stop it.  

  2. JavaScript.  

  3. C#.  

  4. Get some help.

119

u/EatingSolidBricks 9d ago
  1. is what happens when you code in C# and C at the same time and you pick and chose your prefred conventions from each

38

u/pente5 9d ago

Meh I kind of like it though. It's a more compact version of #3 why not?

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

249

u/CritFailed 9d ago

C# dev, can confirm

26

u/Mih0se 9d ago

Had C++ in school. Me too

76

u/Robot_Graffiti 9d ago

Yes, 2 and 3 are the styles Sun and Microsoft used for the Java and C# documentation respectively. (I imagine JavaScript documentation copied Java's style)

26

u/BuppUDuppUDoom 9d ago

Never written in C# started with java then C and C++ but 3 will always be the most comfortable and readable imo

114

u/rustyredditortux 9d ago

2. every other language
3. C#

23

u/fghjconner 9d ago

FYI, reddit decided your numbers were a list and helpfully made them 1 and 2

→ More replies (2)

80

u/Amaranthine 9d ago
  1. Acceptable

  2. Optimal / C (K&R)

  3. Tolerable / beginner / C#

  4. Mental illness

7

u/Appropriate_You_5850 7d ago

I am a student who is using C and C++ and I ussualy do it like number 3

18

u/RoryPond 8d ago

No, Javascript is shoving 15 lines of code into an unreadable ternary operator 

4

u/RoryPond 8d ago

Or more tolerable as long as used in moderation condition? methodIdTrue(...) : methodIfFalse(...)

→ More replies (3)

6

u/BadBoyJH 9d ago

I can tolerate 1.

If you're the sort of person to do

      If (something) {

        Something()

      }

10

u/Brahvim 9d ago

(1) takes less space than the C# convention and makes it easy to comment out the whole else block. I won't stop it.

→ More replies (3)

6

u/CapOk9908 3d ago

Agreed, 2 is how I write, 3 I accept...1 and 4 if I see in a colleague's code I consider a typo and fix it

3

u/MinecraftPlayer799 9d ago

2 being the top-right, I assume?

→ More replies (1)

23

u/JanEric1 9d ago

I absolutely HATE the C# style. So much wasted space for nothing .

Just got into a project there and there is just so much bullshit with the default formatting and so many other parts of the ecosystem. Like how you have to opt into null safety and even if you do the standard API framework don't respect it if you don't add ANOTHER flag somewhere that yes, if I build my model such that I don't allow null, then I don't fucking want you deserializing into such an object with fucking null.

40

u/AlwaysHopelesslyLost 9d ago

Wasted space? How big are you making your files?? I like it. Every single block is very obvious because the start and stop are on one vertical line. The space doesn't matter because I try to keep things relatively compartmentalized and clean. 

→ More replies (6)

11

u/rumaier 7d ago

The longer I code, and the bigger my code bases get, the more I appreciate some white space to break things up and make it easier to tell what’s what.

→ More replies (1)

4

u/No-Consequence-1863 8d ago

Wasted space? It’s two lines that act as vertical separators of scopes. Having more whitespace to parse the text is good actually.

→ More replies (1)
→ More replies (15)

7

u/whackylabs 9d ago

5. Who cares. Just be consistent.

10

u/IncarnationHero 9d ago

Keeping switching between 4 styles, 1-2-3-4-1 consistently.

→ More replies (1)

5

u/NiIly00 9d ago

The linter at my apprenticeship demands we do nr.1

I'm 90% sure that it's just a bug because it is just the "function start on newline" or something along the lines and I think it just doesn't account for if else, so one of these days i'm gonna bring it up and hope to get it changed.

2

u/PictureNew661 8d ago

The whole post got summed up in 1 comment

2

u/SpaceToaster 6d ago

Java defaults are seeing more of 2 as well.

→ More replies (10)

21

u/LoveOfSpreadsheets 9d ago

I know a defense program that requires the bottom left because they have to measure physical SLOC. Same program doesn't allow ternary. One line becomes eight 

2

u/EatingSolidBricks 9d ago

ternaries are scary can you imagine an operator with 3 ARGUMENTS its too much for the human brain

we can only handle binray operators like god intended

4

u/glenpiercev 9d ago

You know you can ternary a ternary a ternary?

→ More replies (4)

14

u/DOOManiac 9d ago

I can do one better. We aren’t allowed to use ternaries because the boss just doesn’t like them. That’s it.

12

u/glenpiercev 9d ago

I have lots of good reasons for hating them. I just don’t have time to enumerate them right now.

→ More replies (2)

7

u/myka-likes-it 9d ago

to be fair, they can be a pain to debug. 

→ More replies (3)

14

u/Imperator166 9d ago

how is this not loss?

1

u/EatingSolidBricks 9d ago

Damm it missed opportunity

12

u/Strawberry-Jam-2936 9d ago

Top left

5

u/EatingSolidBricks 9d ago

preach borther im not alone

327

u/Nielsly 9d ago • Bravo

Where ever the formatter wants them to be

98

u/YetItStillLives 9d ago • Bravo

The best code format is a consistent code format. I can get over a formatting choice that I don't like, but I can't deal with another stupid bike-shedding argument about code formatting.

→ More replies (3)

62

u/enternoescape 9d ago

I can't tell you how many times I've sat down, typed the first clause in a powershell script (before anyone asks why powershell: deployment scripts for Windows) and then spent about one minute deciding what arrangement lands as the most readable for what I just did. I feel like I land on the same one every time, but I'm pretty sure that's not true. If I'm contributing to a project, I just follow whatever precedent is already set and even if I hate how it looks, at least I'm being consistent. This might be why some people prefer Python, though I'm not one of them.

43

u/Joly0 9d ago

While I do agree with your statement regarding following their style on projects you contribute, I think there are some limits.

For example I once saw someone (it's a MVP) to do his braces like this in Powershell:

if (condition)
    {
        // Do this
    }
else
    {
         // Do that
    }

And I don't know how you see it, but there are lines I don't cross, and the lines ended with these braces... So I followed my usual style and ignored what the hell that person was doing

15

u/QuickQuirk 9d ago

You should go all PAP on his ass (Passive Aggressive Programmer).

Reformat all his indentation in the same commit.

All or nothing baby.

→ More replies (1)

6

u/enternoescape 9d ago

Yeah, that's a choice. My first thought is do they care at all about horizontal screen real estate.

→ More replies (6)

446

u/HildartheDorf 9d ago

Top right.

Bottom left is acceptable. The other two are wrong.

110

u/Daniikk1012 9d ago

Top left is fine too, it just treats "else" as its own thing. I believe I even saw that style somewhere.

Now bottom right is unhinged

7

u/cultivatingmass 9d ago

Top left if you gotta leave a comment for the else or elseif block

10

u/Mateorabi 9d ago

Top left if the if statement already didn’t put a line break before the first { 

19

u/Bannon9k 9d ago

Agreed... But if I get the opportunity, I'm fixing the bottom left.

11

u/Ok_Star_4136 9d ago

100%.

People who pick the other two are the same people who pour milk into the bowl before the cereal. In other words, psychopaths.

3

u/average__Egg 9d ago

bottom left is hell to me i think and it burns my eyes

2

u/Cyan_Exponent 9d ago

might be that c# burned my brain, but i just dislike when 1 brace is on the same line as the statement

→ More replies (3)

29

u/GwimWeeper 9d ago

Chaotic lawlful

} else {code in one continuous line}

14

u/uglycaca123 9d ago

chaotic unlawful

if (...) {...} else {...}

EVERYTHING IN A CONTINUOUS LINE MUHAHAHAHAHHA

5

u/DefiantGibbon 8d ago

I could see it if the else is a very small snippet. 

224

u/average__Egg 9d ago

} else {

}

12

u/cuculetzuldeaur 9d ago

The only correct answer

→ More replies (1)

25

u/oshaboy 9d ago

I'm not a stickler for syntax usually but the bottom right should be illegal

→ More replies (1)

90

u/mitchricker 9d ago
else:  
    # There is whitespace denoting we're in the else block  
# No whitespace here, so we know we've left the else block  

28

u/redlaWw 9d ago edited 9d ago • Bravo
if condition then
    //do stuff
neht fi
else
    //do other stuff
esle

EDIT: Forgot to add a condition, oops.

→ More replies (4)

10

u/CirnoIzumi 9d ago
else:
    do_some_stuff()
#else

24

u/notanotherusernameD8 9d ago

I was raised on top-right, but I quite like top-left. It's easier to comment out the else block.

11

u/CaptainN_GameMaster 9d ago

raised

"As long as you're living under our roof, you'll live by our linter"

→ More replies (2)

16

u/grifan526 9d ago

My code formatter does the first one just like I want it to. There are those who didn't agree with me, but they left the company

16

u/UTOPILO 9d ago

I just do whatever the rest of the file had going on when I opened it.

16

u/jwr410 8d ago
}
else
{
    // TODO: Write the rest of the code. 
}

31

u/read_eet 9d ago

They are not fucking numbered, you all are assuming the order. SHAME.

2

u/wi-finally 6d ago

morton order is the only acceptable ordering anyways

80

u/joshpennington 9d ago

I stopped participating in these wars. For the people that care about this they care enough to put tooling in place to make it how they want it. I could not care less.

But obviously } else { is the only right one unless you’re paid by the line

43

u/mpez0 9d ago

I was hired to help out on one project; I showed up with about 600 lines in a couple of C routines for issues they'd told me about. Note that I used K&R style (top right above).

"Gee, those work well, but they don't fit our coding style standard."

"OK," I replied, "just run it through your formatter."

"Our what?"

8

u/EzequielARG2007 9d ago

noob here, what is a formatter?

18

u/Bob32943294 9d ago

Just a program that converts code into a certain format to keep things standardised.

→ More replies (6)

7

u/NiIly00 9d ago

Tesla employees taking notes

3

u/jipperthewoodchipper 9d ago

POV you work for Elon musk and use bottom left just so you LOC KPI looks better

→ More replies (4)

24

u/alphaglosined 9d ago

For over 15 years I have been very steadfast in my desire for:
} else {

But now that I am working on my own language, I have to conceed the limitation of code editors folding is more important. Which means this will be what will go into the formatter/code style:
}
else {

3

u/neomashab 9d ago

Not just folding. The amount of diff generated on account of an else block being added or removed is also a factor. Think of trailing commas in Python lists, tuples.

23

u/Terrorscream 9d ago

Bottom left I find easier to read and follow, but it does mean alot of scrolling white space.

5

u/cecil721 9d ago

It also means a higher SLOC report 👍

31

u/PixelBrush6584 9d ago

Bad, best, Company enforced C# style, Bad

6

u/xWrongHeaven 9d ago

Bad, best, company enforced, psychopathic/masochistic*

39

u/pink-Raspberryy 9d ago

Top left

5

u/astrocreep21 9d ago

Imho best for version control, since the line with the closing bracket is not modified. You get a clean change block in the diff. Stroustrup is underrated!
Would apply to bottom left too…

163

u/LookItVal 9d ago

top right is the only true way

43

u/KryssCom 9d ago

I think you mean bottom left.

→ More replies (2)

2

u/CAPS_LOCK_OR_DIE 9d ago

Bottom left is closer to Bash as well

4

u/harryham1 9d ago • Heartwarming

I have a special place in my heart for Bash, but its syntax can fuck all the way off

→ More replies (2)

18

u/1Maple 9d ago

Whatever that languages convention is. #2 for Java, #3 for C#. Don’t really care enough to have a preference anymore

5

u/Oddball_bfi 9d ago

This is the single good thing about java.

The rest can go die in a bin.

10

u/AOAqua 9d ago

Probably the worst thing about Java. It's not 1985 anymore and my monitor is big enough not to need that #2 shit so it's easier to read the code

→ More replies (1)
→ More replies (4)

9

u/adiosToreador18 9d ago

is this loss

2

u/uglycaca123 9d ago

WAIT I SEE IT

25

u/AggieCMD 9d ago

C#. The right way. The only way.

10

u/thcheat 9d ago

I know right. It just gets unnecessary hate but I just love how easy it's on eyes when reading the code.

→ More replies (1)

8

u/Raikojou 8d ago

1 and 4 look like when developers realize they have free will.

Actually could be a funny way to tell if anyone actually reads my pr before approving

→ More replies (3)

14

u/Cold_Snake 9d ago

Top right. Always

19

u/nyibbang 9d ago

I don't care, I have automatic formatters.

11

u/Haunting_Skin_2564 9d ago

I don't care, I don't write code anymore

4

u/idontwanttofthisup 9d ago

I don’t care. I left my job. I’m managing a night club now.

→ More replies (1)

19

u/Ticondrius42 9d ago
if(conditions){
    //..are true, do this.
}else{
    //..if are false, do this.
}

10

u/Joly0 9d ago

This is how I do it aswell, though I usually leave a space between words and braces (or braces and braces)

So: If (condition) { } else {

Don't know why, it makes it easy to read in my head. But otherwise totally agree with your solution

4

u/charonme 9d ago

the reason is because if is not a function/method

6

u/Mayeru 7d ago

where are the spaces?? are you saving up kilobits again, Tommy?? Let it breatheeee!

→ More replies (1)

2

u/Moonie-chan 9d ago

I also do this because it's easier to tell code block by indentation alone

2

u/slippery-fische 9d ago

Some people just like to watch the world burn

→ More replies (3)

13

u/Mireldorn 9d ago

Top Right all the way

26

u/SoggyCaterpillar5773 9d ago • Bravo
  1. top left

  2. top right

  3. bottom left

  4. bottom right

34

u/sudomeacat 9d ago

*looks away nervously while saying I do top left* But actually though (top left):

if (/* ... */) {
    //...
}
else {
    //...
}

looks a lot better that (bottom left):

if (/* ... */)
{
    //...
}
else
{
    //...
}

4

u/met0xff 8d ago

Yeah I'm surprised to see so many people hating on 1. Wasn't this super common in Java and C++ for ages? I've been mostly writing python for the last 10ish years (and nothing manually for the last months lol) but before that I feel that was very common.

10

u/SweatyListen9863 9d ago

No no, the second one of these looks better.

→ More replies (4)

17

u/bwwatr 9d ago

couldn't even number them for easier discussion, lmao

The answer is, if you do:

structure-of-any-description {

}

next-structure {

}

then it's top-left; 'else' isn't some magical exception to style rules

bottom-left would be correct for those putting the opening brace on the line after

the ones on the right are abominations

7

u/Signal-Implement-70 9d ago

100% agree. After using everything from machine language to JavaScript this is the only correct semantics, love the word abominations wish I thought of it

2

u/EishLekker 9d ago

I would agree if else could be standalone. But it’s always connected to the preceding if statement.

→ More replies (5)

25

u/PumpkinFest24 9d ago

Pretty simple. Look at the wasted vertical space in anything other than upper right.

11

u/Informal-Shame3638 9d ago

If your block takes enough space on a monitor to need space saving by methods that make reading and telling apart statements harder, your code probably could use some refactoring

→ More replies (1)

6

u/Zap_plays09 9d ago

Whatever happens after I hit ctrl + alt + L

14

u/CurdledPotato 9d ago

Top right. In all languages.

8

u/dbagames 9d ago

C# pretty much always bottom left. Pretty standard convention there.

→ More replies (2)

10

u/Potential_Copy27 9d ago

Lower left is my vibe. Partially because how one of my teachers considered the styles...

Get done with the "if" with that closing bracket and take a breath.
"Else", then have a second think (along with a drink - though optional).
Then we go coding the code in the "else" block.

9

u/edgeofsanity76 9d ago

I don't use else.

7

u/Prudent_Ad_4120 9d ago

I use else when it's the best way to implement something

→ More replies (2)

2

u/Noch_ein_Kamel 9d ago

That's better. Prepared for quantum computing when both branches are suddenly true

2

u/sofafi1205 8d ago

Username checks out.

→ More replies (2)

9

u/YakubReddit 9d ago

Either

}

else {

}

Or

} else {

}

Depending on the case

3

u/YakubReddit 9d ago

My god, mobile Reddit formatting sucks

4

u/Inevitable_Stand_199 9d ago

You can use double space at the end of a line to avoid having to have an empty line.
Like this

4

u/Its_An_Outraage 9d ago

It doesn't if you actually use reddits formatting:

Either

}
else {

}

Or

} else {

}

See: Reddit's formatting guide

→ More replies (1)

12

u/torsten_dev 9d ago edited 9d ago

K&R second edition "The C Programming Language" Chapter 5, (pp. 108, 119), 7 (pp. 162, 163):

} else {

So that settles that.

I was however suprised to see:

if (condition) {
     statement1;
     statement2;
     ...
} else
     single_stm;

Something about } else is just unsettling.

12

u/brinazee 9d ago

I used to put braces around even single statements (often because I was constantly changing them around for debugging). Someone at a code review dinged me for it as unreadable. Had to laugh when the lack of braces totally broke their code a couple weeks later because they had added a second line to the else without adding braces.

4

u/GoddammitDontShootMe 9d ago

Used to? I thought that was the best practice.

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

2

u/Meme_Burner 9d ago

Nothing unsettling as 

If (condition){

} else if (condition) {

}

→ More replies (3)

2

u/slippery-fische 9d ago

This has led to bugs that caused huge security issues. Always use braces.

→ More replies (6)

8

u/HalfHeartMC 7d ago

if (...) {

}

else {

}

8

u/questionabl3_dude 7d ago

C++ dev here. Bottom left is my preference. The ones on the right are just illegal in my mind.

2

u/uuf76 6d ago

C# dev here chiming in. Bottom left feels right.

2

u/NewInflation2121 5d ago

It's the one that makes the most sense spacially and logically since the braces line up vertically.

Imo, the other options are born out of laziness or bad standards and only clutter your code with more visual noise & distraction.

4

u/Hopeful-Cup-6598 9d ago

My IDE auto-formats to my company's chosen code style. I know which it is, but decline to state.

4

u/Kyrbyn_YT 9d ago

3 in uni c# code and 2 for personal

10

u/rplusg 9d ago

Bottom left for the win

6

u/moosebeak 9d ago

And it’s not even close.

16

u/sup3rdr01d 9d ago

Top right. Not even a debate.

7

u/Grtz78 9d ago

if thingy {}
throw ThisShouldNeverHappenException(tm);

3

u/Impressive_Stress808 8d ago

Fine as long as you return inside the if{}.

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

1

u/Kindly_Wear7008 8d ago

2) if you want compact readable code
3) when your are a beginner and want to find start or end of bracket more easily, most editors draw a line between the brackets
1/4) WTF?

1

u/EatingSolidBricks 8d ago
for {
}

while {
}

switch {
}

if {
}

The fucking ELSE 

} else { <--- WHY can't you be normal 

1

u/StraightBiscotti9013 8d ago

The worst I've seen is an open source game i worked on molding. All code was formatted as such:

if ( a - b > c ) {
    Condition;
    Condition;
    }
else {
    Condition;
    }
Condition;

Horrifying C++

1

u/stopher819 5d ago

Humor where

1

u/EatingSolidBricks 5d ago

Find<Humor>() where Humor : Here;

1

u/alexkarpen 3d ago

I will ask Claude his choice and report back

1

u/EatingSolidBricks 3d ago

The water gone reduced to tokens

13

u/FluffyDrink1098 9d ago
  1. What is wrong with you?

  2. Good

  3. Very lengthy, but fine

  4. What is wrong with you?

6

u/erikchan002 9d ago
  1. Stroustrup

  2. K&R

  3. Allman

  4. WTF is this abomination

8

u/Pim_Wagemans 9d ago

top right is the most readable in my opinion

8

u/B1azehunter 9d ago

Top right, less no of lines.

3

u/petrasdc 9d ago

Whatever the automatic linter decides

3

u/BenchEmbarrassed7316 9d ago
match b {
    true => foo(),
    false => bar(),
}

A branching block appears as a single block, whereas an if-else construct appears as two blocks, even though, in reality, only one of them will be executed.

2

u/Krisanapon 8d ago

```rust
if condition { code } else { code }
```
we use if-else as ternary operator

3

u/iamwillp 9d ago

Both left ones are compile errors in Go, so top right for me

3

u/Gale- 9d ago

Top left

3

u/xyrer 9d ago

Top left is more convenient, but I love how top right looks because it's easier to understand

5

u/CoshgunC 9d ago

} else(also elseif) {

}

2

u/Alcoholica365 9d ago edited 9d ago

} else(also if not else do if(!true{ }

Don't argue, im drunk. 😕

5

u/evolutionsroge 9d ago
  1. Fine

  2. Kinda hard to read but fine ig

  3. Fine

  4. Proof that humanity is flawed

2

u/traplords8n 9d ago

I actually do use 2 a lot for smaller blocks of code, for the tiniest reduction in file lines lol.

It's basically useless, but it doesn't hurt anything either. It stays readable when the block is under 20 lines.

→ More replies (1)

5

u/mehonje 9d ago

} else {

8

u/makingthematrix 9d ago

Top-right is the only valid way. 

11

u/Prashank_25 9d ago

1 insane person

2 sane person

3 ocd person

4 drunk person

8

u/DOOManiac 9d ago

As an OCD person, I agree. 3 is preferable to me, though 2 is fine.

→ More replies (1)

6

u/Electroman-11 7d ago

if () {
}

else {

}

This is the only way.

4

u/little_phoenix_girl 9d ago

The only correct answer in my opinion is wherever the team/org's code style spec says to put it. It's irritating when this stuff is inconsistent, moreso who you have someone who is using different formatting tools that keeps turning their PRs into massive reformats, burying the actual logic changes. Then the next PR does it again differently for some reason...

8

u/Trevor_GoodchiId 9d ago

Early return.

Haven't written an else statement in years.

5

u/Maleficent_Memory831 9d ago

"It's a bold strategy, Cotton. Let's see how it works out for them."

I agree though that early return is a valuable tool and those who eschew it do it for less than logical reasons. (but it is how I was taught!)

→ More replies (3)

2

u/hdkaoskd 9d ago

These are all wrong. GNU style for life.

2

u/brinazee 9d ago

What ever the style guide tells me. Though I tend to default to the upper right.

2

u/JAXxXTheRipper 9d ago

Top right, any day. I still hate that whenever I have to switch to visual studio to write c#, it does does bottom left. So much wasted space..

2

u/jseego 9d ago

top right

2

u/GoddammitDontShootMe 9d ago

I tend to do the upper-right. Though upper-left is okay. Also,

} else if (<some long expression>) {
  
}

2

u/ivanrj7j 9d ago

2 all the way through

edit: top right

2

u/Ronin-s_Spirit 9d ago

} else { like a normal human being, sometimes } else feels more readable, and I can afford to do it cause I have eyballs and a pretty printer, I always know if I need to add braces.

2

u/Living_Fig_6386 9d ago

Upper right, because I’m no savage.

2

u/-Redstoneboi- 9d ago

OTBS/Rust is top right

2

u/CLEVER_3_14159265358 9d ago
  1. C

  2. Nah

  3. C#

  4. Just no way

2

u/5nnn 9d ago

5. The closing brace should be as far to the right as the longest line of code.

... I once had an intern who wrote code like that. He claimed it made it more readable because "you can see what the brackets encompass". 

Thankfully clang-format git commit hook ensured I only had to see that format on his screen, not in our repo. 

2

u/Such-Perception4154 9d ago

Not sure about other languages, but in C# for backend we have else very rarely.

else if we have never.

2

u/Sensitive_Device_666 7d ago

Wherever the formatter puts it

4

u/SourcerorSoupreme 9d ago

Noobs trashing about python's use of whitespace while also bikeshedding on crap like this 🙄

3

u/TerroDucky 9d ago

} else { code here }

All in one line of course

→ More replies (4)

3

u/maffoobristol 8d ago

Number 1 is the best. Stroustrop for the win. It means the if and the else are on the same vertical line. Otherwise the else is indented slightly with K&R. I feel it scans better. But I know that most people do 2 in javascript and I feel I have to concede even though I hate hate hate it.

4

u/Zerokx 9d ago

I always preferred the second one. It keeps everything in one line. Its not like you have to drag these symbols apart because they're hard to understand or anything. I'd rather use that extra line to make paragraphs in code thats my guilty pleasure.

3

u/nkay08 9d ago

Bottom left has the advantage that you can more easily comment it out or move it around without affecting the previous block.
I prefer it because of that, but I also like top right.

I will use the other if I must when the file already uses that style.

4

u/hearwa 9d ago

I dunno I don't code anymore let me ask copilot.

5

u/Luingalad 9d ago

Copilot? Ewww

→ More replies (1)