Skip to content
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

Stroustrup style braces #219

Closed
wavded opened this issue Aug 3, 2015 · 8 comments
Closed

Stroustrup style braces #219

wavded opened this issue Aug 3, 2015 · 8 comments
Labels

Comments

@wavded
Copy link

wavded commented Aug 3, 2015

a.k.a.

if (true) {
}
else {
}

instead of

if (true) {
} else {
}

My intention isn't to bikeshed here. More curious for an explanation as it doesn't seem like any strong opinion was expressed. My current style matches almost all of Standard except this one. I like this option because I can put comments above and it keeps the keyword on the left side (easier to see).

if (true) {
}
// Otherwise we will do yada yada
else {
}

Thanks for the excellent lib btw!

@feross feross added the question label Aug 3, 2015
@jprichardson
Copy link
Member

I actually agree with this, but I'm thinking it may be too late to change.

Making the change now would dramatically affect all of standard users. I also would wonder if it would hurt the tool's perception of stability (assuming it has this perception). Any kind of style change like this would have to be for a very good reason.

@feross
Copy link
Member

feross commented Aug 4, 2015

This is one of the decisions in standard where we 'just picked something'. Here's what the readme says about this:

At the end of the day you have to 'just pick something', and that's the whole philosophy of standard -- its a bunch of sensible 'just pick something' opinions.

You make a good point about comments being a little more readable in Stroustrup style, though. :)

This is one of those decisions that we can't revisit. Nearly every repo that uses standard would break, and that's not acceptable -- even with major version bump.

(If it really matters to you, consider using eslint-shareable-config and overriding this one rule.)

Thanks for the thoughtful issue!

@feross feross closed this as completed Aug 4, 2015
@wavded
Copy link
Author

wavded commented Aug 4, 2015

Fair point and thanks for the response. For now I'm just overriding that rule and perhaps I'll adapt later.

@timwis
Copy link

timwis commented Jan 12, 2016

Hey guys, thanks again for the background on this. Forgive me for resurrecting an old question but I can't help but notice one thing you said:

Nearly every repo that uses standard would break

Just to clarify, what I was talking about, at least, would be a rule such as:

else { must be on the same line as closing curly } or be preceded by a comment line

This way existing repos would not break, as } else { would be valid. But repos could also use:

// Test x condition
if (foo) {
}
// Otherwise, y
else {
}

To be clear, I'm not trying to make a case -- just trying to clarify that I didn't mean "instead of" the current rule but an additional allowance. If this still doesn't make sense in standard, no worries. In that case, one thing that would be helpful, though, would be guidance on where to put those comments in a consistent way. Some options:

// Test x condition
if (foo) {
} else { // Otherwise, y
}
if (foo) {
  // Test x condition
} else {
  // Otherwise, y
  // Though this doesn't stand out nearly as much when there's code in this block
}
if (foo) {
// Test x condition
  var x = y
} else {
// Otherwise, y (on same indent level as curly brackets)
  var x = z
}

Thanks for taking the time to reply

@dcousens
Copy link
Member

// the true case
if (true) {

// the false case
} else {

}

Is the convention for comments I follow.
I don't think the

if (...) {
}
else {

}

syntax is in the spirit of standard (that is, try and enforce only 1 way to do things).

@yoshuawuyts
Copy link
Contributor

I concur with @dcousens

@timwis
Copy link

timwis commented Jan 12, 2016

Nice! Hadn't thought of that, thanks

@eddiemonge
Copy link

That looks so ugly and to me the comment looks related to the if statement, not the else.

@standard standard locked as resolved and limited conversation to collaborators Mar 2, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
Archived in project
Development

No branches or pull requests

7 participants