r/programminghumor • • Oct 02 '26

the battle of else part 2

Post image
0 Upvotes

39 comments sorted by

47

u/AdrianParry13526 Oct 02 '26

```
if (…) {
…
}
else {
…
}
```

8

u/TOGoS Oct 02 '26

I call this one "Dad style"

4

u/asmanel Oct 02 '26

Not surprising, this one is an echo of the Basic.

0

u/[deleted] Oct 02 '26

[deleted] — view deleted comment

3

u/TOGoS Oct 02 '26

Who, me? Or my dad?

I don't think most vibe coders give a hoot about brace style, if they even know what a curly brace is.

-17

u/Financial_Counter_45 Oct 02 '26

I see... the cursed ones

3

u/IAmBroke_0001 Oct 02 '26

Schizo posting

22

u/swimmv28493 Oct 02 '26

My job’s coding standards require me to do it this way
if
{
…
}
else
{
…
}

6

u/Iwisp360 Oct 02 '26

Oh no newline braces

2

u/ChrisBot8 Oct 02 '26

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."

2

u/asmanel Oct 02 '26

Pros :

  • This air the code
  • This artificially increase the number of lines

Cons :

  • The part of code visiible at the same time is lower
  • This get more disk memory

1

u/Right_Ear_2230 Oct 17 '26

Like, a few bytes more disk space

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/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.

5

u/Iwisp360 Oct 02 '26

Why? if with a space and then the condition would be telling you at first glance that this is an if stmt and then the condition

if (x > 2) {

}

1

u/NamedBird Oct 02 '26

But the parentheses are part of the structure, not part of the condition.
You literally cannot have an "if" keyword without them!

(And whether you want a space between ) and { is up to you.)

boolean myBool = x > 2;
if( myBool ){
  // statements
}

// OR

if( x > 2 ){
  // statements
}

3

u/Iwisp360 Oct 02 '26

You literally cannot have an "if" keyword without them!

Have you ever used rust? This is valid rust code

if x > 1 {
}

3

u/ChrisBot8 Oct 02 '26

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.

1

u/NamedBird Oct 02 '26

C, C++, i believe even Java? (There are many more though.)

After the IF keyword, the only valid non-whitespace character is the "(".

3

u/ChrisBot8 Oct 02 '26

Right but white space is valid, so it is not wrong

1

u/NamedBird Oct 02 '26

Welcome to C++, you will never know everything! 🤣

2

u/ChrisBot8 Oct 02 '26

Well yes, but I believe you can do `if (#statement)` just not `if true`

1

u/NamedBird Oct 02 '26

Go try it yourself if you don't believe me...

2

u/ChrisBot8 Oct 02 '26

Just did. Exactly what I said works. The compiler does care about the “(“ being after the if, but doesn’t care about the space.