The Chromium style guide says:
--
--
Chromium Developers mailing list: chromi...@chromium.org
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-dev
// When it requires multiple lines, indent 4 spaces, putting the colon on // the first initializer line: MyClass::MyClass(int var) : some_var_(var), // 4 space indent some_other_var_(var + 1) { // lined up ... DoSomething(); ... }
I had the same question and filed this internal bug against clang-format: http://b/9620984The summary is that the style arbiters said one line is fine, though that's Google of course, not Chromium. I feel like Chromium doesn't have any reason to diverge from Google style here.
MyClassWithALongName::MyClassWithALongName(int var): some_var_(var), some_other_var_(var + 1) {DoSomething();}
--
On Thu, Aug 22, 2013 at 12:09 PM, Peter Kasting <pkas...@chromium.org> wrote:
> This is something like the fourth case I've seen recently where clang-formatWhen you run into things like this, please file bugs against
> does something in the range of "less common in Chrome code" to "arguably
> illegal by the Chrome style guide". I have to say that the more of these I
> run into, the less favorable I feel towards people using clang-format to
> format code.
clang-format.
Well, as long as we keep our style guide ambiguous, a tool like clang-format is not that helpful.
If we decided that it wasn't important enough to have a style rule about, then it shouldn't be important enough to nit on CLs about.
I explicitly disagree with this. If a particular file, directory, or subsystem is consistent about style X, then in general new code in that scope should follow style X, and if it doesn't, the reviewer _should_ complain about it.
The style guide is a tool to enforce the ultimate goal of consistency, as opposed to consistency being a goal insofar as it is necessary to fulfill the letter of the style guide.
On Thu, Aug 22, 2013 at 12:38 PM, Peter Kasting <pkas...@chromium.org> wrote:
I explicitly disagree with this. If a particular file, directory, or subsystem is consistent about style X, then in general new code in that scope should follow style X, and if it doesn't, the reviewer _should_ complain about it.
Isn't this arguing for fiefdoms of enforced, conflicting styles within Chromium? I would think we would want to discourage that. Chromium code is Chromium code. If the team as a whole thinks two styles for some minor thing are essentially equally readable, what's the benefit to the team in creating enforced pockets of differences, just because a local owner likes that style better?
but also mandates as the single most important rule that people "be consistent with the surrounding code".
Jeffrey
--
In the meantime, I cringe about changes like this landing in the code and being used as precedent for other changes.
--
I've been doing research in preparation for filing clang-format bugs for these two issues. For the first example you gave where it collapsed a single-line body on to the same line as the { and }, I find at least two style rules that apply:- The open curly brace is always at the end of the same line as the last parameter.- The close curly brace is either on the last line by itself or (if other style rules permit) on the same line as the open curly brace.Doesn't following the second rule by definition violate the first rule?
The style guide itself gives an example (that doesn't compile) that does this: http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml?showone=Namespaces#Namespaces -- search for AtEof(). Offhand, I don't know if there are other style rules that would prohibit 3 lines from being collapsed into 1, but that doesn't mean they don't exist.
Apologies in advance for digging up an old thread, and a formatting one at that. But.. from a code review I was doing, clang-format was done and it did two things:in x.cc, it changedvoid Foo::Bar() {DoY();}tovoid Foo::Bar() { DoY(); }which I haven't seen in our code before or in the style guide.Also, in a header it changedvoid LongFunctionName(type parameter1,type parameter2) OVERRIDE;tovoid LongFunctionName(type parameter1,type parameter2)OVERRIDE;
On Mon, Apr 7, 2014 at 2:43 PM, John Abd-El-Malek <j...@chromium.org> wrote:
> Apologies in advance for digging up an old thread, and a formatting one atIIRC, this one happened when they made single-line functions collapse
> that. But.. from a code review I was doing, clang-format was done and it did
> two things:
>
> in x.cc, it changed
> void Foo::Bar() {
> DoY();
> }
>
> to
> void Foo::Bar() { DoY(); }
>
> which I haven't seen in our code before or in the style guide.
to one line in header files. e.g.
https://code.google.com/p/chromium/codesearch/#chromium/src/content/browser/browsing_instance.h&sq=package:chromium&q=BrowsingInstance::browser_context&type=cs&l=61
I probably can't post to chromium-dev, but I assume that enough people will get this email..
About override/OVERRIDE: If you read the comment back-log on the mentioned document you can see that I brought this up, but my approach was overruled. We all overlooked the necessity for this inside Chromium's codebase, though, so I'll see what I can do.About short functions on a single line: I am not going to implement any further support beyond the flag AllowShortFunctionsOnASingleLine (which you can set to whatever value in Chromium's .clang-format) file.
I probably can't post to chromium-dev, but I assume that enough people will get this email..
About override/OVERRIDE: If you read the comment back-log on the mentioned document you can see that I brought this up, but my approach was overruled. We all overlooked the necessity for this inside Chromium's codebase, though, so I'll see what I can do.About short functions on a single line: I am not going to implement any further support beyond the flag AllowShortFunctionsOnASingleLine (which you can set to whatever value in Chromium's .clang-format) file. I personally don't think that more complex rules are an improvement or matter in any significant way (readability or consistency), but I appreciated that opinions differ.
On Mon, Apr 7, 2014 at 11:10 PM, Daniel Jasper <dja...@google.com> wrote:
I probably can't post to chromium-dev, but I assume that enough people will get this email..
About override/OVERRIDE: If you read the comment back-log on the mentioned document you can see that I brought this up, but my approach was overruled. We all overlooked the necessity for this inside Chromium's codebase, though, so I'll see what I can do.About short functions on a single line: I am not going to implement any further support beyond the flag AllowShortFunctionsOnASingleLine (which you can set to whatever value in Chromium's .clang-format) file.We shouldn't set anything in our .clang-format file except style=Chromium. If we feel that any of the defaults for style=Chromium aren't good, we should change what style=Chromium means in clang-format. It'd be silly if chromium used "style=Chromium, but with the following changes" :-)
To be clear, since I mangled my words: the ToT clang-format adds newlines in Chromium mode, even if the {}'s are empty.On Fri, Apr 11, 2014 at 3:33 PM, Nick Carter <ni...@chromium.org> wrote:
I'm in the process of rolling new clang-format binaries, I'm noticed that it also will also add newlines to non-inline empty function bodies:That is, the new clang-format does this:PanelInformation::~PanelInformation() {}instead of this:PanelInformation::~PanelInformation() {}
On Fri, Apr 11, 2014 at 3:35 PM, Nick Carter <ni...@chromium.org> wrote:
To be clear, since I mangled my words: the ToT clang-format adds newlines in Chromium mode, even if the {}'s are empty.On Fri, Apr 11, 2014 at 3:33 PM, Nick Carter <ni...@chromium.org> wrote:
I'm in the process of rolling new clang-format binaries, I'm noticed that it also will also add newlines to non-inline empty function bodies:That is, the new clang-format does this:PanelInformation::~PanelInformation() {}instead of this:PanelInformation::~PanelInformation() {}
Isn't the first style against the style guide? It says: "The open curly brace is always at the end of the same line as the last parameter.", to me that reads that for non-inlined method definitions, nothing should be after the open curly brace.
On Fri, Apr 11, 2014 at 3:40 PM, John Abd-El-Malek <j...@chromium.org> wrote:
On Fri, Apr 11, 2014 at 3:35 PM, Nick Carter <ni...@chromium.org> wrote:
To be clear, since I mangled my words: the ToT clang-format adds newlines in Chromium mode, even if the {}'s are empty.On Fri, Apr 11, 2014 at 3:33 PM, Nick Carter <ni...@chromium.org> wrote:
I'm in the process of rolling new clang-format binaries, I'm noticed that it also will also add newlines to non-inline empty function bodies:That is, the new clang-format does this:PanelInformation::~PanelInformation() {}instead of this:PanelInformation::~PanelInformation() {}
Isn't the first style against the style guide? It says: "The open curly brace is always at the end of the same line as the last parameter.", to me that reads that for non-inlined method definitions, nothing should be after the open curly brace.oops, I mean the "Isn't the second style"
On Fri, Apr 11, 2014 at 3:40 PM, John Abd-El-Malek <j...@chromium.org> wrote:
On Fri, Apr 11, 2014 at 3:35 PM, Nick Carter <ni...@chromium.org> wrote:
To be clear, since I mangled my words: the ToT clang-format adds newlines in Chromium mode, even if the {}'s are empty.On Fri, Apr 11, 2014 at 3:33 PM, Nick Carter <ni...@chromium.org> wrote:
I'm in the process of rolling new clang-format binaries, I'm noticed that it also will also add newlines to non-inline empty function bodies:That is, the new clang-format does this:PanelInformation::~PanelInformation() {}instead of this:PanelInformation::~PanelInformation() {}
Isn't the first style against the style guide? It says: "The open curly brace is always at the end of the same line as the last parameter.", to me that reads that for non-inlined method definitions, nothing should be after the open curly brace.oops, I mean the "Isn't the second style"
void Circle::Rotate(double /*radians*/) {}
MyClass::MyClass(int var) : some_var_(var), some_other_var_(var + 1) {}
X::X() : X("") { } (whoah really? - nick
On Fri, Apr 11, 2014 at 3:40 PM, John Abd-El-Malek <j...@chromium.org> wrote:
On Fri, Apr 11, 2014 at 3:40 PM, John Abd-El-Malek <j...@chromium.org> wrote:
On Fri, Apr 11, 2014 at 3:35 PM, Nick Carter <ni...@chromium.org> wrote:
To be clear, since I mangled my words: the ToT clang-format adds newlines in Chromium mode, even if the {}'s are empty.On Fri, Apr 11, 2014 at 3:33 PM, Nick Carter <ni...@chromium.org> wrote:
I'm in the process of rolling new clang-format binaries, I'm noticed that it also will also add newlines to non-inline empty function bodies:That is, the new clang-format does this:PanelInformation::~PanelInformation() {}instead of this:PanelInformation::~PanelInformation() {}
Isn't the first style against the style guide? It says: "The open curly brace is always at the end of the same line as the last parameter.", to me that reads that for non-inlined method definitions, nothing should be after the open curly brace.oops, I mean the "Isn't the second style"I don't think one-line is prohibited by the language you linked to, nor by the style guide in total, which has a few "good code" example snippets (copied below) that use the one-line style. The codebase being split fifty-fifty is evidence that at best we're tolerant of both, or at worst that we have a population of reviewers insisting on one style or the other, inconsistently.void Circle::Rotate(double /*radians*/) {}MyClass::MyClass(int var) : some_var_(var), some_other_var_(var + 1) {}X::X() : X("") { } (whoah really? - nick
To be clear, since I mangled my words: the ToT clang-format adds newlines in Chromium mode, even if the {}'s are empty.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-dev...@chromium.org.
On Fri, Apr 11, 2014 at 3:35 PM, Nick Carter <ni...@chromium.org> wrote:
To be clear, since I mangled my words: the ToT clang-format adds newlines in Chromium mode, even if the {}'s are empty.That would be particularly upsetting for at least inline empty functions in header files.Use case:class FooDelegate: {public:virtual A() {}virtual B() {}virtual C() {}
};Compared to:
class FooDelegate: {public:virtual A() {}virtual B() {}virtual C() {}};
The new version of clang-format will put these examples on one line, as you prefer, because they're inline. It's non-inline functions that are affected.
On Fri, Apr 11, 2014 at 4:44 PM, Nick Carter <ni...@chromium.org> wrote:
The new version of clang-format will put these examples on one line, as you prefer, because they're inline. It's non-inline functions that are affected.I see. Then I don't care much (aside of the churn).
On Fri, Apr 11, 2014 at 5:15 PM, Antoine Labour <pi...@google.com> wrote:
On Fri, Apr 11, 2014 at 4:44 PM, Nick Carter <ni...@chromium.org> wrote:
The new version of clang-format will put these examples on one line, as you prefer, because they're inline. It's non-inline functions that are affected.I see. Then I don't care much (aside of the churn).`git cl format` only formats lines touched by a CL, so this hopefully won't cause a ton of churn.
The new version of clang-format will put these examples on one line, as you prefer, because they're inline. It's non-inline functions that are affected.
--
I'm in the process of rolling new clang-format binaries, I'm noticed that it also will also add newlines to non-inline empty function bodies:That is, the new clang-format does this:PanelInformation::~PanelInformation() {}instead of this:PanelInformation::~PanelInformation() {}
I implemented the option "BreakBeforeTernaryOperators" about half a year ago, but apparently forgot to change the default for Chromium (or at least start a discussion about it). If you come to a conclusion, you can put a corresponding setting in Chromium's .clang-format file and I'll then port that back to the default settings for the built-in Chromium style.
PK
PK
I think this has been discussed extensively for the google c++ style guide, and clang-format's behavior is what has been ruled as "correct" (even though it's not super common internally either). We try not to differ from google-internal formatting more than necessary.
--
It seems like more recently we've finally begun agreeing that, where Chromium code tries to be consistent about doing something else, and that something is not in violation of the internal guide, we should make clang-format preserve that style in Chromium code.
As for "operators go on the ends of lines", I think it's worth pointing out that there are already two pretty consistent exceptions to this rule. Both << and . tend to be placed at the start of the line rather than the end when wrapping is required.
Semantically, <- and . are pretty close in meaning... so at least for me, it doesn't make sense to be inconsistent between the two.
Either we should place both at the end of a line or both at the beginning.
On Mon, Apr 14, 2014 at 12:22 PM, Peter Kasting <pkas...@chromium.org> wrote:
It seems like more recently we've finally begun agreeing that, about doing something else, and that something is not in violation of the internal guide, we should make clang-format preserve that style in Chromium code.
I think we should have a clear (and, preferably, high) bar for imposing our personal style preferences on clang-format and chromium.Personally, I'd go so far as saying that if it's not completely obvious that Chrome has already decided on a particular style, we should be accepting the default clang-format style (or convincing them that what they are doing is wrong). It makes everyone's life easier. Examples of things that would be completely obvious: it's in Chromium's style guide, a significant majority of instances in Chrome do it a certain way, etc.
Side note: could we maybe create a different group for these c-style discussions?
Here are some numbers from two years ago (arbitrarily chosen, hopefully mostly pre clang-format) and today-ish for the dot operator:
On Sun, Apr 13, 2014 at 4:34 AM, Daniel Jasper <dja...@google.com> wrote:
I implemented the option "BreakBeforeTernaryOperators" about half a year ago, but apparently forgot to change the default for Chromium (or at least start a discussion about it). If you come to a conclusion, you can put a corresponding setting in Chromium's .clang-format file and I'll then port that back to the default settings for the built-in Chromium style.I know I've raised the issue of ternary formatting twice before -- it's long been my biggest objection to clang-format's formatting -- so it would be nice to make clang-format do the right thing. Could you just go ahead and make the change without a third discussion on it?
To be clear, the setting should be such that we progressively wrap like this:a ? b : c;a ?b : c;
a ?b :c;The rationale for this is that this is not only the prevalent style (indeed, before clang-format began being used at all, it was nearly-universal), it's more consistent with the style guide rule about placing operators on the ends of lines.
PK
On Mon, Apr 14, 2014 at 12:22 PM, Peter Kasting <pkas...@chromium.org> wrote:
It seems like more recently we've finally begun agreeing that, where Chromium code tries to be consistent about doing something else, and that something is not in violation of the internal guide, we should make clang-format preserve that style in Chromium code.
I think we should have a clear (and, preferably, high) bar for imposing our personal style preferences on clang-format and chromium.
Personally, I'd go so far as saying that if it's not completely obvious that Chrome has already decided on a particular style, we should be accepting the default clang-format style (or convincing them that what they are doing is wrong). It makes everyone's life easier. Examples of things that would be completely obvious: it's in Chromium's style guide, a significant majority of instances in Chrome do it a certain way, etc.Side note: could we maybe create a different group for these c-style discussions? And then better document decisions that come of them? Having the discussions go to both lists would even work for me. I think it is very hostile to new, and even relatively experienced, devs to have the decisions that come of these discussions completely hidden among the mass of chromium-dev threads. It leads the decisions being inconsistently enforced and I don't think we should have codereview discussions like:reviewer: don't do this, do this other thingauthor: ok sure. Is there anywhere I can read more about why?reviewer: there's a chromium-dev thread from a couple years ago about it(author goes off and searches for "refcounted" on chromium-dev and finds ~2 weeks worth of reading material)
--
On Mon, Apr 14, 2014 at 9:09 PM, Peter Kasting <pkas...@chromium.org> wrote:
On Sun, Apr 13, 2014 at 4:34 AM, Daniel Jasper <dja...@google.com> wrote:
I implemented the option "BreakBeforeTernaryOperators" about half a year ago, but apparently forgot to change the default for Chromium (or at least start a discussion about it). If you come to a conclusion, you can put a corresponding setting in Chromium's .clang-format file and I'll then port that back to the default settings for the built-in Chromium style.I know I've raised the issue of ternary formatting twice before -- it's long been my biggest objection to clang-format's formatting -- so it would be nice to make clang-format do the right thing. Could you just go ahead and make the change without a third discussion on it?Sure, all I ask is that you check it in to Chromium's .clang-format file to have a basic decision process behind such changes. I'll port everything I find there back as soon as I can.
On Mon, Apr 14, 2014 at 1:19 PM, Chris Hopman <cjho...@chromium.org> wrote:
On Mon, Apr 14, 2014 at 12:22 PM, Peter Kasting <pkas...@chromium.org> wrote:
It seems like more recently we've finally begun agreeing that, where Chromium code tries to be consistent about doing something else, and that something is not in violation of the internal guide, we should make clang-format preserve that style in Chromium code.
I think we should have a clear (and, preferably, high) bar for imposing our personal style preferences on clang-format and chromium.+1. I'm happy to see this thread, but it seems to have run off into the weeds. The value of easy to use consistent automatic formatting is higher than debating how we mostly-ish used a given pattern of indents. The value is in consistency and ease of use, not chromium flavors.
On Tue, Apr 15, 2014 at 7:06 AM, Vincent Scheib <sch...@chromium.org> wrote:
On Mon, Apr 14, 2014 at 1:19 PM, Chris Hopman <cjho...@chromium.org> wrote:
On Mon, Apr 14, 2014 at 12:22 PM, Peter Kasting <pkas...@chromium.org> wrote:
It seems like more recently we've finally begun agreeing that, where Chromium code tries to be consistent about doing something else, and that something is not in violation of the internal guide, we should make clang-format preserve that style in Chromium code.
I think we should have a clear (and, preferably, high) bar for imposing our personal style preferences on clang-format and chromium.+1. I'm happy to see this thread, but it seems to have run off into the weeds. The value of easy to use consistent automatic formatting is higher than debating how we mostly-ish used a given pattern of indents. The value is in consistency and ease of use, not chromium flavors.And I have long said that if we want to run clang-format over the whole codebase, and then make it a mandatory (and automatic) part of submission, then I don't care what kind of formatting it does. (Personally, I think this would be the best possible route forward; however, no one seems to want to bother.)The problem occurs when the codebase is mostly not clang-formatted, and the clang-format formatting is a sharp change from what the rest of the codebase is doing.
In that case there is no "consistency" advantage. If we want consistency, we need to either not use clang-format, use it everywhere, or continue the current pattern of having some people use it some places but ensure that the tools' output matches existing code -- yes, including patterns of indents.
PK
On Tue, Apr 15, 2014 at 12:49 PM, Peter Kasting <pkas...@chromium.org> wrote:
The problem occurs when the codebase is mostly not clang-formatted, and the clang-format formatting is a sharp change from what the rest of the codebase is doing.
I think most others don't perceive the clang-format output as sharply different.
1. Reformat whole codebase. Pro: Could switch to the regular google style guide. Cons: Blame output becomes unusable.
Also, since clang-format changes every now and then, we wouldn't have the forever-consistency you seem to desire (or we'd have to do global reformats frequently.)
2. Keep codebase as-is, let people format code how they want, but add a rule "reviewers must not leave style nits on clang-formatted changes".
Pro: Most people don't feel more strongly about getting their stuff done than formatting (or so I claim), so most people would be happy about getting their code in more quickly. Cons: Requires clang-format to be "good enough".