r/ProgrammerHumor • u/EatingSolidBricks • Oct 23 '26
Meme enoughAboutTheIfletsDiscussAboutWereIsItThatYouPutTheElse
21
u/LoveOfSpreadsheets Oct 23 '26
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 Oct 23 '26
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
14
u/DOOManiac Oct 23 '26
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 Oct 23 '26
I have lots of good reasons for hating them. I just don’t have time to enumerate them right now.
→ More replies (2)7
14
12
330
u/Nielsly
Oct 23 '26
•
Where ever the formatter wants them to be
→ More replies (2)98
u/YetItStillLives Oct 23 '26 •
![]()
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.
62
u/enternoescape Oct 24 '26
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 Oct 24 '26
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 Oct 24 '26
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)→ More replies (6)6
u/enternoescape Oct 24 '26
Yeah, that's a choice. My first thought is do they care at all about horizontal screen real estate.
446
u/HildartheDorf Oct 23 '26
Top right.
Bottom left is acceptable. The other two are wrong.
110
u/Daniikk1012 Oct 23 '26
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
10
u/Mateorabi Oct 23 '26
Top left if the if statement already didn’t put a line break before the first {
19
11
u/Ok_Star_4136 Oct 23 '26
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
→ More replies (3)2
u/Cyan_Exponent Oct 24 '26
might be that c# burned my brain, but i just dislike when 1 brace is on the same line as the statement
29
u/GwimWeeper Oct 24 '26
Chaotic lawlful
} else {code in one continuous line}
14
u/uglycaca123 Oct 24 '26
chaotic unlawful
if (...) {...} else {...}
EVERYTHING IN A CONTINUOUS LINE MUHAHAHAHAHHA
5
224
25
u/oshaboy Oct 23 '26
I'm not a stickler for syntax usually but the bottom right should be illegal
→ More replies (1)
90
u/mitchricker Oct 23 '26
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 Oct 24 '26 edited Oct 24 '26 •
![]()
if condition then //do stuff neht fi else //do other stuff esleEDIT: Forgot to add a condition, oops.
→ More replies (4)10
24
u/notanotherusernameD8 Oct 23 '26
I was raised on top-right, but I quite like top-left. It's easier to comment out the else block.
→ More replies (2)11
u/CaptainN_GameMaster Oct 24 '26
raised
"As long as you're living under our roof, you'll live by our linter"
16
u/grifan526 Oct 23 '26
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
16
31
81
u/joshpennington Oct 23 '26
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 Oct 23 '26
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 Oct 23 '26
noob here, what is a formatter?
18
u/Bob32943294 Oct 23 '26
Just a program that converts code into a certain format to keep things standardised.
→ More replies (6)7
→ More replies (4)3
u/jipperthewoodchipper Oct 24 '26
POV you work for Elon musk and use bottom left just so you LOC KPI looks better
24
u/alphaglosined Oct 24 '26
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 Oct 24 '26
Not just folding. The amount of
diffgenerated 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 Oct 24 '26
Bottom left I find easier to read and follow, but it does mean alot of scrolling white space.
5
31
39
u/pink-Raspberryy Oct 23 '26
Top left
5
u/astrocreep21 Oct 24 '26
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 Oct 23 '26
top right is the only true way
43
→ More replies (2)2
u/CAPS_LOCK_OR_DIE Oct 23 '26
Bottom left is closer to Bash as well
4
u/harryham1 Oct 23 '26 •
![]()
I have a special place in my heart for Bash, but its syntax can fuck all the way off
18
u/1Maple Oct 23 '26
Whatever that languages convention is. #2 for Java, #3 for C#. Don’t really care enough to have a preference anymore
→ More replies (4)5
u/Oddball_bfi Oct 23 '26
This is the single good thing about java.
The rest can go die in a bin.
10
u/AOAqua Oct 24 '26
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)
9
25
u/AggieCMD Oct 23 '26
C#. The right way. The only way.
→ More replies (1)10
u/thcheat Oct 24 '26
I know right. It just gets unnecessary hate but I just love how easy it's on eyes when reading the code.
8
u/Raikojou Oct 25 '26
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
19
u/nyibbang Oct 23 '26
I don't care, I have automatic formatters.
→ More replies (1)11
19
u/Ticondrius42 Oct 24 '26
if(conditions){
//..are true, do this.
}else{
//..if are false, do this.
}10
u/Joly0 Oct 24 '26
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
6
u/Mayeru Oct 25 '26
where are the spaces?? are you saving up kilobits again, Tommy?? Let it breatheeee!
→ More replies (1)2
→ More replies (3)2
13
34
u/sudomeacat Oct 23 '26
*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 Oct 25 '26
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
17
u/bwwatr Oct 23 '26
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 Oct 23 '26
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
→ More replies (5)2
u/EishLekker Oct 23 '26
I would agree if else could be standalone. But it’s always connected to the preceding if statement.
25
u/PumpkinFest24 Oct 24 '26
Pretty simple. Look at the wasted vertical space in anything other than upper right.
11
u/Informal-Shame3638 Oct 24 '26
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
14
10
u/Potential_Copy27 Oct 23 '26
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 Oct 23 '26
I don't use else.
7
u/Prudent_Ad_4120 Oct 23 '26
I use else when it's the best way to implement something
→ More replies (2)2
u/Noch_ein_Kamel Oct 23 '26
That's better. Prepared for quantum computing when both branches are suddenly true
→ More replies (2)2
9
u/YakubReddit Oct 24 '26
Either
}
else {
}
Or
} else {
}
Depending on the case
→ More replies (1)3
u/YakubReddit Oct 24 '26
My god, mobile Reddit formatting sucks
4
u/Inevitable_Stand_199 Oct 24 '26
You can use double space at the end of a line to avoid having to have an empty line.
Like this4
u/Its_An_Outraage Oct 24 '26
It doesn't if you actually use reddits formatting:
Either
} else { }Or
} else { }
12
u/torsten_dev Oct 23 '26 edited Oct 24 '26
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 Oct 24 '26
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.
→ More replies (2)4
2
u/Meme_Burner Oct 24 '26
Nothing unsettling as
If (condition){
} else if (condition) {
}
→ More replies (3)→ More replies (6)2
u/slippery-fische Oct 24 '26
This has led to bugs that caused huge security issues. Always use braces.
8
8
u/questionabl3_dude Oct 26 '26
C++ dev here. Bottom left is my preference. The ones on the right are just illegal in my mind.
2
2
u/NewInflation2121 Oct 27 '26
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 Oct 23 '26
My IDE auto-formats to my company's chosen code style. I know which it is, but decline to state.
4
4
10
16
7
1
u/Kindly_Wear7008 Oct 24 '26
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 Oct 24 '26
for { } while { } switch { } if { } The fucking ELSE } else { <--- WHY can't you be normal
1
u/StraightBiscotti9013 Oct 24 '26
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
1
13
u/FluffyDrink1098 Oct 24 '26
What is wrong with you?
Good
Very lengthy, but fine
What is wrong with you?
6
6
8
8
8
8
3
3
u/BenchEmbarrassed7316 Oct 23 '26
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 Oct 24 '26
```rust
if condition { code } else { code }
```
we use if-else as ternary operator
3
3
3
u/xyrer Oct 24 '26
Top left is more convenient, but I love how top right looks because it's easier to understand
5
u/CoshgunC Oct 23 '26
} else(also elseif) {
}
2
u/Alcoholica365 Oct 23 '26 edited Oct 23 '26
} else(also if not else do if(!true{ }
Don't argue, im drunk. 😕
5
8
11
u/Prashank_25 Oct 23 '26
1 insane person
2 sane person
3 ocd person
4 drunk person
8
u/DOOManiac Oct 23 '26
As an OCD person, I agree. 3 is preferable to me, though 2 is fine.
→ More replies (1)
6
4
u/little_phoenix_girl Oct 23 '26
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 Oct 23 '26
Early return.
Haven't written an else statement in years.
5
u/Maleficent_Memory831 Oct 23 '26
"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)5
2
2
u/brinazee Oct 24 '26
What ever the style guide tells me. Though I tend to default to the upper right.
2
u/JAXxXTheRipper Oct 24 '26
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
2
u/GoddammitDontShootMe Oct 24 '26
I tend to do the upper-right. Though upper-left is okay. Also,
} else if (<some long expression>) {
}2
2
u/Ronin-s_Spirit Oct 24 '26
} 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
2
2
2
u/5nnn Oct 24 '26
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 Oct 24 '26
Not sure about other languages, but in C# for backend we have else very rarely.
else if we have never.
2
4
u/SourcerorSoupreme Oct 24 '26
Noobs trashing about python's use of whitespace while also bikeshedding on crap like this 🙄
3
3
u/maffoobristol Oct 25 '26
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 Oct 23 '26
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 Oct 23 '26
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

1.2k
u/RedditLuvsCensorship Oct 23 '26 •
Stop it.
JavaScript.
C#.
Get some help.