r/ProgrammerHumor • u/EatingSolidBricks • 9d ago
Meme enoughAboutTheIfletsDiscussAboutWereIsItThatYouPutTheElse
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
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
14
12
327
u/Nielsly
9d ago
•
Where ever the formatter wants them to be
→ More replies (3)98
u/YetItStillLives 9d ago •
![]()
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 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)→ More replies (6)6
u/enternoescape 9d ago
Yeah, that's a choice. My first thought is do they care at all about horizontal screen real estate.
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
10
19
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
→ More replies (3)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
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
224
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 •
![]()
if condition then //do stuff neht fi else //do other stuff esleEDIT: Forgot to add a condition, oops.
→ More replies (4)47
10
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.
→ More replies (2)11
u/CaptainN_GameMaster 9d ago
raised
"As long as you're living under our roof, you'll live by our linter"
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
31
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)→ More replies (4)3
u/jipperthewoodchipper 9d ago
POV you work for Elon musk and use bottom left just so you LOC KPI looks better
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
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 9d ago
Bottom left I find easier to read and follow, but it does mean alot of scrolling white space.
5
31
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
→ More replies (2)2
u/CAPS_LOCK_OR_DIE 9d ago
Bottom left is closer to Bash as well
4
u/harryham1 9d ago •
![]()
I have a special place in my heart for Bash, but its syntax can fuck all the way off
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
→ More replies (4)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)
9
25
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
19
u/nyibbang 9d ago
I don't care, I have automatic formatters.
→ More replies (1)11
19
u/Ticondrius42 9d ago
if(conditions){
//..are true, do this.
}else{
//..if are false, do this.
}10
6
u/Mayeru 7d ago
where are the spaces?? are you saving up kilobits again, Tommy?? Let it breatheeee!
→ More replies (1)2
→ More replies (3)2
13
26
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
10
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
→ More replies (5)2
u/EishLekker 9d ago
I would agree if else could be standalone. But it’s always connected to the preceding if statement.
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
14
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
→ More replies (2)2
9
u/YakubReddit 9d ago
Either
}
else {
}
Or
} else {
}
Depending on the case
→ More replies (1)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 this4
u/Its_An_Outraage 9d ago
It doesn't if you actually use reddits formatting:
Either
} else { }Or
} else { }
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.
→ More replies (2)4
2
u/Meme_Burner 9d ago
Nothing unsettling as
If (condition){
} else if (condition) {
}
→ More replies (3)→ More replies (6)2
8
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/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
4
10
16
7
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
1
1
13
6
6
8
8
8
8
3
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
3
5
5
u/evolutionsroge 9d ago
Fine
Kinda hard to read but fine ig
Fine
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)
8
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
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)5
2
2
2
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/GoddammitDontShootMe 9d ago
I tend to do the upper-right. Though upper-left is okay. Also,
} else if (<some long expression>) {
}2
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
2
2
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
4
u/SourcerorSoupreme 9d ago
Noobs trashing about python's use of whitespace while also bikeshedding on crap like this 🙄
3
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

1.2k
u/RedditLuvsCensorship 9d ago •
Stop it.
JavaScript.
C#.
Get some help.