The only answer to these style questions is always, "whatever my job's style guide requires. If I get to pick the style guide I pick google's because I don't have to update it myself, so in that case whatever google requires."
The else being on the same line as the closing brace make it more difficult for me to parse at a glance. My brain bundles the else(and for, if, while, etc.) in with the opening brace as a single beginning of block marker, and I need the beginning of a block as the start of the line, otherwise it feels like there's a mismatched closing brace at a glance.
HOWEVER, have you ever considered the " if( " keyword? The "if" and the opening ( belong together, it is the only valid combination. So it would be wrong to put a space inbetween.
I'm sorry what are you talking about? In what language? Do you have a SO or documentation I can read on this? This is the first I'm reading about it in a 10 year career.
47
u/AdrianParry13526 Oct 02 '26
```
if (…) {
…
}
else {
…
}
```
22
u/swimmv28493 Oct 02 '26
My job’s coding standards require me to do it this way
if
{
…
}
else
{
…
}
5
u/_alba4k Oct 02 '26
anything other than 4 (or having things on separate lines, ofc) is madness
5
u/potato-dranik Oct 02 '26
Python programmers be like:
4
u/Lou_Papas Oct 02 '26
I’ll extend my neovim so else statements animate left to right
3
u/xyperpenguin Oct 02 '26
I use the 4th one..
3
u/SleepingGecko Oct 02 '26
I haven’t checked what claude uses
2
u/faultydesign Oct 02 '26
I prefer the allman style indentation but honestly I just follow language standards.
2
u/realmauer01 Oct 02 '26
Ctrl+s
Thats the kind i am.
2
u/errepunto Oct 02 '26
(If condition when-true when-false)
2
u/BoldFace7 Oct 02 '26
if(cond){ } else{ }
The else being on the same line as the closing brace make it more difficult for me to parse at a glance. My brain bundles the else(and for, if, while, etc.) in with the opening brace as a single beginning of block marker, and I need the beginning of a block as the start of the line, otherwise it feels like there's a mismatched closing brace at a glance.
2
u/Sockoflegend Oct 02 '26
Get a linter. You won't regret it
3
u/Altugsalt Oct 02 '26
if
{ ---
} else
{
}
1
u/Confident-Ad5665 Oct 03 '26
I'm old enough to have learned code formating standards from the K&R C book, so I always use:
} else {
1
u/RealRockyMoney Oct 13 '26
Coordinates (0, 0) if I am in a hurry, and if I am relaxed (1, 1)
1
u/Jazzlike_Platypus430 Oct 02 '26
None of these, unless it's js or R 😂
1
u/Amazing_Peach_6690 Oct 02 '26
else: 😀
1
u/rootifera Oct 02 '26
personally, none of these.
else {
stuff goes in here.
}
would be my preference. however, it depends on the project. if I'm joining one, I'dfollow the existing style.
-2
u/NamedBird Oct 02 '26
Spaces are normally fine.
HOWEVER, have you ever considered the " if( " keyword?
The "if" and the opening ( belong together, it is the only valid combination.
So it would be wrong to put a space inbetween.
There is no "if" keyword.