r/ProgrammerHumor • u/EatingSolidBricks • Oct 23 '26
Meme enoughAboutTheIfletsDiscussAboutWereIsItThatYouPutTheElse
989
Upvotes
r/ProgrammerHumor • u/EatingSolidBricks • Oct 23 '26
1.2k
u/RedditLuvsCensorship Oct 23 '26 •
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
14
u/Imperator166 Oct 23 '26
how is this not loss?
12
u/Strawberry-Jam-2936 Oct 23 '26
Top left
331
u/Nielsly Oct 23 '26 •
Where ever the formatter wants them to be
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.
446
u/HildartheDorf Oct 23 '26
Top right.
Bottom left is acceptable. The other two are wrong.
29
u/GwimWeeper Oct 24 '26
Chaotic lawlful
} else {code in one continuous line}
224
u/average__Egg Oct 24 '26
} else {
}
25
u/oshaboy Oct 23 '26
I'm not a stickler for syntax usually but the bottom right should be illegal
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.
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
u/UTOPILO Oct 24 '26
I just do whatever the rest of the file had going on when I opened it.
16
u/jwr410 Oct 25 '26
31
u/read_eet Oct 24 '26
They are not fucking numbered, you all are assuming the order. SHAME.
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
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 {23
u/Terrorscream Oct 24 '26
Bottom left I find easier to read and follow, but it does mean alot of scrolling white space.
31
u/PixelBrush6584 Oct 24 '26
Bad, best, Company enforced C# style, Bad
39
u/pink-Raspberryy Oct 23 '26
Top left
163
u/LookItVal Oct 23 '26
top right is the only true way
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
9
u/adiosToreador18 Oct 24 '26
is this loss
25
u/AggieCMD Oct 23 '26
C#. The right way. The only way.
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
14
u/Cold_Snake Oct 24 '26
Top right. Always
19
u/nyibbang Oct 23 '26
I don't care, I have automatic formatters.
19
u/Ticondrius42 Oct 24 '26
13
u/Mireldorn Oct 24 '26
Top Right all the way
34
u/sudomeacat Oct 23 '26
*looks away nervously while saying I do top left* But actually though (top left):
looks a lot better that (bottom left):
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
25
u/PumpkinFest24 Oct 24 '26
Pretty simple. Look at the wasted vertical space in anything other than upper right.
6
u/Zap_plays09 Oct 23 '26
Whatever happens after I hit ctrl + alt + L
14
u/CurdledPotato Oct 24 '26
Top right. In all languages.
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.
9
u/YakubReddit Oct 24 '26
Either
}
else {
}
Or
} else {
}
Depending on the case
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):
So that settles that.
I was however suprised to see:
Something about
} elseis just unsettling.8
u/HalfHeartMC Oct 25 '26
if (...) {
}
else {
}
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.
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
u/Kyrbyn_YT Oct 23 '26
3 in uni c# code and 2 for personal
4
u/DrScottyB Oct 25 '26
Top right.
10
u/rplusg Oct 24 '26
Bottom left for the win
16
u/sup3rdr01d Oct 24 '26
Top right. Not even a debate.
7
u/Grtz78 Oct 24 '26
if thingy {}throw ThisShouldNeverHappenException(tm);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/StraightBiscotti9013 Oct 24 '26
The worst I've seen is an open source game i worked on molding. All code was formatted as such:
Horrifying C++
1
u/stopher819 Oct 27 '26
Humor where
1
u/alexkarpen Oct 29 '26
I will ask Claude his choice and report back
13
u/FluffyDrink1098 Oct 24 '26
6
u/erikchan002 Oct 24 '26
6
u/simplerisnoteasier Oct 24 '26
4 should be illegal
8
u/Pim_Wagemans Oct 23 '26
top right is the most readable in my opinion
8
u/MinecraftPlayer799 Oct 23 '26
Top-right
8
u/B1azehunter Oct 24 '26
Top right, less no of lines.
8
u/SleepySpeck01 Oct 24 '26
Bottom left.
3
u/petrasdc Oct 23 '26
Whatever the automatic linter decides
3
u/BenchEmbarrassed7316 Oct 23 '26
A branching block appears as a single block, whereas an
if-elseconstruct appears as two blocks, even though, in reality, only one of them will be executed.3
u/iamwillp Oct 23 '26
Both left ones are compile errors in Go, so top right for me
3
u/Gale- Oct 23 '26
Top left
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) {
}
5
u/mehonje Oct 23 '26
} else {
8
u/makingthematrix Oct 24 '26
Top-right is the only valid way.
11
u/Prashank_25 Oct 23 '26
1 insane person
2 sane person
3 ocd person
4 drunk person
6
u/Electroman-11 Oct 25 '26
if () {}else {}This is the only way.
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.
2
u/hdkaoskd Oct 23 '26
These are all wrong. GNU style for life.
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
u/jseego Oct 24 '26
top right
2
u/GoddammitDontShootMe Oct 24 '26
I tend to do the upper-right. Though upper-left is okay. Also,
2
u/ivanrj7j Oct 24 '26
2 all the way through
edit: top right
2
u/Ronin-s_Spirit Oct 24 '26
} else {like a normal human being, sometimes} elsefeels 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 Oct 24 '26
Upper right, because I’m no savage.
2
u/-Redstoneboi- Oct 24 '26
OTBS/Rust is top right
2
u/CLEVER_3_14159265358 Oct 24 '26
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
elsevery rarely.else ifwe have never.2
u/Sensitive_Device_666 Oct 25 '26
Wherever the formatter puts it
4
u/SourcerorSoupreme Oct 24 '26
Noobs trashing about python's use of whitespace while also bikeshedding on crap like this 🙄
3
u/TerroDucky Oct 23 '26
} else { code here }
All in one line of course
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.
4
u/hearwa Oct 23 '26
I dunno I don't code anymore let me ask copilot.
2
u/NoMansSkyWasAlright Oct 23 '26
Wherever the auto-formatter puts them. If IntelliSense wants them one way, I don't care enough to go back and change it.
2
u/dbagames Oct 24 '26
Bottom left in C# 100% of the time.
These conventions depend on the language most of the time.
2
u/C0sm1cJ0k3r Oct 24 '26
I put all my code on a single line like any sane person should.
}else{CodeHere}
2
u/tayler6000 Oct 24 '26
Two and three are the only legitimate options. My preference is option 2, but I’ll conform when I’m in C# since that is the official style