if
statement has no else
or else if
clauses, then the curly braces for the controlled statement or the line breaks inside the curly braces may be omitted if as a result the entire if
statement appears on either a single line (in which case there is a space between the closing parenthesis and the controlled statement) or on two lines (in which case there is a line break after the closing parenthesis and there are no braces). For example, the following forms are allowed under this exception." and we are explicitly allowed to not make use of this exception: "Some projects require curly braces always."--
You received this message because you are subscribed to the Google Groups "cxx" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cxx+uns...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/cxx/CAGFX3sHfmFDrNt4UyGT5ZTGNa9WhhifmfVhdgLpxYiE2br3ukA%40mail.gmail.com.
Personally I'm a fan of the single-line ifs omitting braces, but I'm a bigger fan of code style that's enforceable by clang-format that has a shot at being globally consistent. Just like I don't want to think about indentation, I also want to stop considering whether the current file uses if (foo) bar(); or if (foo) { bar(); } as we currently permit both but should be locally consistent.
if (multiline &&
condition)
return b;
if (multiline &&
condition) {
return b;
}
if (single line condition)
return b;
--
You received this message because you are subscribed to the Google Groups "cxx" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cxx+uns...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/cxx/CAAHOzFDs%2BKoQ_-SAcCk0YFqHYkYtEfQmxuHWMApNZ-zCKhuFkA%40mail.gmail.com.
Then if the condition becomes shorter later, I may be asked to take the braces back off again (for consistency, I suppose):if (single line condition)
return b;This is pointless churn, in my opinion.
--
You received this message because you are subscribed to the Google Groups "cxx" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cxx+uns...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/cxx/CAGFX3sG%2BvwyH_0mB%2BjD_zcCBz9trc6FtNAjmG-v1z_WjG856fA%40mail.gmail.com.
FWIW I think the easiest way to get folks to Not Care At All Ever about this is to have the tool care for you.
I concur that having the formatter handle this is superior to pushing back on reviewers. For one thing, the reviewers are often right about inconsistency, so you at least need to expend additional mental effort having those discussions about whether it really matters or not. We could reduce this to Zero instead of Some Small Number.
I'm not entirely sure what the selling point of allowing the braceless style is at this point, other than saving one vertical line for the terminal "}". That doesn't seem like it has enough value to avoid automating the formatting. I think the onus should be on the historical rule to show that it's valuable enough not to adopt the modern rule.
--
You received this message because you are subscribed to the Google Groups "cxx" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cxx+uns...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/cxx/a32c5b15-5849-442f-8a4d-0016fad1ec0an%40chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/cxx/CAJJNyZZXb0kqem8TyahJ9pJDqfU0Aoa6okLGb8MQAV-P-u2%2BdA%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/cxx/CAGSB53FQ_8-5p3JxUmFahw0zGjJ3PjeFnqJowZiBXBb-r13syw%40mail.gmail.com.
FWIW I think the easiest way to get folks to Not Care At All Ever about this is to have the tool care for you.
--
You received this message because you are subscribed to the Google Groups "cxx" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cxx+uns...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/cxx/CAGFX3sG%2BvwyH_0mB%2BjD_zcCBz9trc6FtNAjmG-v1z_WjG856fA%40mail.gmail.com.
* One macro instance in windows_types.h got a redefinition warning because {0} got changed to { 0 } or something like that.
* Formatting check_unittest.h breaks because __LINE__ changes for a macro invocation.
* Reordering windows.h caused compile errors
However we've previously handled this by putting includes of windows.h in a separate block so that clang-format leaves them alone. See crrev.com/c/4048781 for a patch that would fix this issue in all of base. Thoughts?
--
You received this message because you are subscribed to the Google Groups "cxx" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cxx+uns...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/cxx/CAGFX3sG_tCykFeVRogAEutJgDH%2Bccm-CNhRGt5WAETufckMdcg%40mail.gmail.com.
I support using {}s universally and enabling the new InsertBraces clang-format option for enforcement.However, I am less enthusiastic of re-clang-formatting the codebase. In the end, hitting reformatting CLs in blame/history is a "constant" amount of pain, but it's just one more thing that makes life harder. The older if statements that I'm likely to have questions about are also the ones that are more likely to have braces inserted.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/cxx/f79f795d-3a18-43da-86bd-dc097835d79dn%40chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/cxx/f79f795d-3a18-43da-86bd-dc097835d79dn%40chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/cxx/f79f795d-3a18-43da-86bd-dc097835d79dn%40chromium.org.
Hi folks,I'd like to start a discussion on changing our brace policy for single-line ifs, and I assume this discussion is brought up every N years but I'd like to bring it up again. Specifically I'd like to transform:if (foo)bar();into:if (foo) {bar();
}
Personally I'm a fan of the single-line ifs omitting braces, but I'm a bigger fan of code style that's enforceable by clang-format that has a shot at being globally consistent. Just like I don't want to think about indentation, I also want to stop considering whether the current file uses if (foo) bar(); or if (foo) { bar(); } as we currently permit both but should be locally consistent.The style guide recommends always using braces, but does allow an exception for historical reasons which Chromium does make use of: "For historical reasons, we allow one exception to the above rules: if anif
statement has noelse
orelse if
clauses, then the curly braces for the controlled statement or the line breaks inside the curly braces may be omitted if as a result the entireif
statement appears on either a single line (in which case there is a space between the closing parenthesis and the controlled statement) or on two lines (in which case there is a line break after the closing parenthesis and there are no braces). For example, the following forms are allowed under this exception." and we are explicitly allowed to not make use of this exception: "Some projects require curly braces always."I would like for us to stop making use of this exception, and update the Chromium .clang-format style to include the "InsertBraces" option (and also upstream it to the clang-format "Chromium" style). To try this out, I applied it to //base here. Patchset 1 is just applying clang-format without the .clang-format change to include InsertBraces so that the diff only concerns InsertBraces.
Applying clang-format to //base caused the following build errors:
* One macro instance in windows_types.h got a redefinition warning because {0} got changed to { 0 } or something like that.
* Reordering windows.h caused compile errors
* Formatting check_unittest.h breaks because __LINE__ changes for a macro invocation.
None of these errors look related to InsertBraces and reverting these changes caused the build to pass trybots. I believe this means that it's feasible to apply InsertBraces at scale. I'm happy splitting out the style decision from whether to actually apply clang-format retroactively, but if reformatting is a prerequisite for this change I'd be happy to own this transform.One additional benefit from InsertBraces is that it's also able to fix existing style violations which I've spotted in multiple files (if-else without brackets): https://chromium-review.googlesource.com/c/chromium/src/+/4031901/5/base/allocator/partition_allocator/page_allocator.ccHopefully this means we can paint our bikeshed red, even if you'd prefer for it to be blue, because a machine can paint and keep it red for us in the future, so we can focus on the bikeshed interior. WDYT?Best,Peter
--
You received this message because you are subscribed to the Google Groups "cxx" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cxx+uns...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/cxx/CAGFX3sHfmFDrNt4UyGT5ZTGNa9WhhifmfVhdgLpxYiE2br3ukA%40mail.gmail.com.
I don't have a strong opinion on this, but when reconsidering decisions I think it's a good idea to ask "what changed since we made the decision last time?". This prevents churn.
So, what's changed since the last time we made the decision?
I can think of a few things that changed that make this _less_ desirable in the past: Absence of braces lead to bugs like the famous "goto fail": https://www.imperialviolet.org/2014/02/22/applebug.html We've since mitigated this type of bug in not just one but two ways: We now build with both -Wunreachable-code and -Wmisleading-indentation.One thing that has maybe changed is that we rely on clang-format more. But getting the benefit of not having to worry about braces with clang-format could also be achieved by teaching clang-format to insert braces only for ifs with bodies longer than 1 line.
So I'm fairly lukewarm about the proposal.
Like others on this thread I'm strongly against rewriting the codebase for this. I don't see any benefit in that, and it's a ton of churn.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/cxx/CAMGbLiEKQLSQrji5NkHaC%3DXhxjUrqKqytX-283ikeJxwd%2BacRw%40mail.gmail.com.
So, what's changed since the last time we made the decision?
getting the benefit of not having to worry about braces with clang-format could also be achieved by teaching clang-format to insert braces only for ifs with bodies longer than 1 line.
Like others on this thread I'm strongly against rewriting the codebase for this. I don't see any benefit in that, and it's a ton of churn.
--
You received this message because you are subscribed to the Google Groups "cxx" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cxx+uns...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/cxx/CAAHOzFBV18BwFNTEy_BH%3DRKXDen%2BL2EDYVtbSvWyKhv34fk81A%40mail.gmail.com.
Hi folks, this got landed last friday as crrev.com/c/4048911 and almost immediately reverted as crrev.com/c/4076867.While we tested InsertBraces of all of //base before trying to land this, we did not sufficiently try everyday use with git cl format. It looks like partial formatting breaks down pretty badly (breaks control flow, yikes), see more details in crbug.com/1395455. The ~2 hours of this being checked in was enough to get two bugs filed, I do not believe that the breaking formatting is a one-off.I don't know if there's a good path towards addressing any of these issues, and I don't see that we have built consensus on "let's adopt insert braces" without a tool that can enforce it. So I think status quo right now is that we haven't changed the law of the land, and if we want to take this further we'd need to fix clang-format to deal better with partial-file formatting when InsertBraces is enabled. I don't have the expertise to do so nor any hunch on how hard that would be. I'll likely mark these bugs as available and call them blocked on tooling support that doesn't break control flow this readily.
Thanks folks,Peter--On Tue, Nov 29, 2022 at 11:40 AM K. Moon <km...@chromium.org> wrote:I agree that we've converged on:1. Let's adopt insert braces.2. Let's not reformat everything yet.I don't think there's been any major movement on this thread since the Thanksgiving holiday, so I'm happy to consider this decided.On Tue, Nov 29, 2022 at 11:36 AM 'Peter Kasting' via cxx <c...@chromium.org> wrote:--On Tue, Nov 29, 2022 at 9:37 AM Nico Weber <tha...@chromium.org> wrote:So, what's changed since the last time we made the decision?The main thing, IMO, is that the Google style guide has taken an opinionated stance that with-braces is the one true way, and all other routes are exceptions for historical reasons only. While Chrome qualifies for those historical exceptions, the last time we had a large debate about this, the style guide was more evenhanded about it all.getting the benefit of not having to worry about braces with clang-format could also be achieved by teaching clang-format to insert braces only for ifs with bodies longer than 1 line.Yes, this was my recommendation. Consensus seems to have been "we want the consistency now and no one is volunteering to do this work". :/Like others on this thread I'm strongly against rewriting the codebase for this. I don't see any benefit in that, and it's a ton of churn.To keep things focused, let's agree that as part of THIS debate thread, rewriting everything is out of scope; If we want to rewrite everything, that debate should be its own thread, and it should be justified by things like "we've changed a bunch of style rules" or "clang-format output has changed a lot" and the very real question of "how do we avoid wasting people's time in git blame" should be sufficiently addressed.PK
You received this message because you are subscribed to the Google Groups "cxx" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cxx+uns...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/cxx/CAAHOzFBV18BwFNTEy_BH%3DRKXDen%2BL2EDYVtbSvWyKhv34fk81A%40mail.gmail.com.
You received this message because you are subscribed to the Google Groups "cxx" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cxx+uns...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/cxx/CAGFX3sH6c-J%3DfrC9DyWOQjLDoC3LMCrcrED04kqPQm6HPfJ9kA%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/cxx/CAGFX3sGcpSGBJdLL0OSb0XZ2b%3DtjHOEUsTBPigS_RLZsinU6qw%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/cxx/CACwGi-4JYmxLMP17yr%3D2do2_gRZYNNY9cYqEQJWcncgzDVqSKg%40mail.gmail.com.
I think even with the code fully formatting we haven't proven that a partial git cl format will always do the right thing
Splitting thread to talk about the git blame aspect:We already have a .git-blame-ignore-revs file with a bunch of cleanup commits in it, large scale changes have already happened, so as raised it'd be nice to fix it [1].Is this just setting the local git config to use .git-blame-ignore-revs for everyone (I see a bunch of depot_tools and other config so guess this is supported) and teaching codesearch to respect the file or is there more to it?
I think it's worth snoozing on this one a little bit.If we're right in that control flow breaks with -lines but not otherwise that seems like a bug that upstream can consider (clang-format has enough semantic info to do the right thing, but doesn't) and we can revisit this if anything changes. I'd suspect that's a bug worth fixing to upstream regardless of our discussion.
I wouldn't want to patch any of our tools to workaround an upstream bug or always use full. Especially if not preceded by a mass rewrite but also because a clang-format roll would make unrelated changes show up in code review all the time.
Changing the rules to always require braces without tool support opens up the floodgates to nit:brace in every code review following which seems churntastic I hope we don't need to consider that.
My personal feeling is that if blame was simply blazingly fast, the extra layers wouldn't matter as much. And then we wouldn't have to worry about "should this CL appear in blame or not" which is going to be super non-obvious for a lot of things. And stuff like refactoring, changing APIs, etc, should be in blame but is also noisy depending on what a user is trying to accomplish.
--
You received this message because you are subscribed to the Google Groups "cxx" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cxx+uns...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/cxx/CAGFX3sGYwRwnAJNYESSEk3iLjRZqReERV8MrmPmUhhdYTCEF7A%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/cxx/CAJTZ7LK1FTBi8LULzT8DTcC2WNz%2BLf6Vyw_MSO2d2PRxSHBSDQ%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/cxx/CAF1j9YMnkABksjg36AWGeJxnE-ZGx5BKB444R1AwzZthnfdqkA%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/cxx/CAHtyhaSUH3_vAY9jB%3D2_Fh9WOJNt3JnDSe6mvXP8rbz%2BUjT%3D2g%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/cxx/CAJTZ7LLXpO0y7DsJXdM2dcjF91rLtUS4he3daq3qbt_BnibDAA%40mail.gmail.com.
I'm not disputing it's doable; I just find it annoying especially when files have been renamed and moved over time. This is especially the case in Blink, where I have to skip past both reformattings and renames.
Daniel
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/cxx/CAHtyhaRjhHQ_Tjw41-7JmettxsbdKExq1no%2B_j8VL-XZTHB_Uw%40mail.gmail.com.