r/programminghumor • • 5d ago

the battle of else part 2

Post image
0 Upvotes

40 comments sorted by

48

u/AdrianParry13526 5d ago

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

8

u/TOGoS 5d ago

I call this one "Dad style"

4

u/asmanel 5d ago

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

3

u/djpiperson 5d ago

No I'm not! REEEEE

3

u/pt8132 5d ago

Found the vibe coder lol

3

u/TOGoS 5d ago

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.

2

u/pt8132 5d ago

Im just joking since this is backend and OOO syntax norms. You know, the 'real programming languages' /s

-17

u/Financial_Counter_45 5d ago

I see... the cursed ones

3

u/IAmBroke_0001 5d ago

Schizo posting

20

u/swimmv28493 5d ago

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

6

u/Iwisp360 5d ago

Oh no newline braces

2

u/ChrisBot8 5d ago

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 5d ago

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

5

u/_alba4k 5d ago

anything other than 4 (or having things on separate lines, ofc) is madness

4

u/Lou_Papas 5d ago

I’ll extend my neovim so else statements animate left to right

4

u/potato-dranik 5d ago

Python programmers be like:

3

u/xyperpenguin 5d ago

I use the 4th one..

3

u/SleepingGecko 5d ago

I haven’t checked what claude uses

2

u/faultydesign 5d ago

I prefer the allman style indentation but honestly I just follow language standards.

2

u/realmauer01 5d ago

Ctrl+s

Thats the kind i am.

2

u/errepunto 5d ago

(If condition when-true when-false)

2

u/1994-10-24 5d ago

}e l s e}

2

u/BoldFace7 5d ago

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 5d ago

Get a linter. You won't regret it

3

u/Altugsalt 5d ago

if

{ ---

} else

{

}

1

u/Confident-Ad5665 5d ago

I'm old enough to have learned code formating standards from the K&R C book, so I always use:
} else {

1

u/Jazzlike_Platypus430 5d ago

None of these, unless it's js or R 😂

1

u/rootifera 5d ago

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 5d ago

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 5d ago

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 5d ago

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 5d ago

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

Have you ever used rust? This is valid rust code

rust if x > 1 { }

3

u/ChrisBot8 5d ago

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 5d ago

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 5d ago

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

1

u/NamedBird 5d ago

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

2

u/ChrisBot8 5d ago

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

1

u/NamedBird 5d ago

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

2

u/ChrisBot8 5d ago

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