Skip to content

Why cuddled elses? (brace style) #1709

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
merlinstardust opened this issue Jan 26, 2018 · 1 comment
Closed

Why cuddled elses? (brace style) #1709

merlinstardust opened this issue Jan 26, 2018 · 1 comment
Labels

Comments

@merlinstardust
Copy link

For control statements, why do you prefer elses to be on the same line as the if ending brace? 16.2

Under 8.3 - wrapping parens, you state that wrapping parens shows clearly where the function starts and ends.

I think that having the else block start on the same line is less clear than if it starts on a separate line. This is especially the case if the code blocks are small. You might read the if and skip over else entirely.

Currently preferred - same line

if (test) {
  thing1();
} else {
  thing2();
}

vs
Separate lines

if (test) {
  thing1();
}
else {
  thing2();
}
@ljharb
Copy link
Collaborator

ljharb commented Jan 26, 2018

This is a subjective preference, but specifically, the else is part of the if - it's not a separate piece - so it shouldn't begin a new line.

In general, we follow One True Brace Style.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants