SummaryThe Chromium style guide and clang-format disagree about how to linebreak around the "?:" operator, and we'd like to resolve things. Your opinion about which way to go is sought.BackgroundThe Google style guide does not give much guidance about linebreaking around operators (other than "be consistent when breaking boolean expressions"). In the early days of Chrome, we added a rule to our style guide to clarify this: basically, "break after operators, not before". Thus, when linebreaking around "?:", almost all code did something like:int x = foo ?a :b;When clang-format began to be used, it introduced a new style of breaking before the "?:" operator, e.g.:int x = foo? a: b;
This form, while previously fairly unknown in the codebase, is now up to ~30% of cases, compared with ~70% for the other form**, due to the increasing popularity of clang-format.clang-format actually has a flag to control which way it breaks around these operators, but Chromium doesn't explicitly toggle the flag.ChoiceI'm seeking to harmonize our practice by making one of the two above the officially-encouraged style for Chromium. Here are the pros for each as I see them:Break after ?:+ Consistent with the great majority of existing code+ Obeys explicit Chromium style recommendation (which was deemed important enough to preserve even when we removed most other exceptions from Google style)+ Consistent with most binary operators, e.g. +, -, &&, etc., where we break after, not before+ Highly subjective: Seems more readable to me, somewhat so to NicoBreak before ?:+ Insofar as clang-format is the representation of "official Google style", more consistent with Google style+ Almost no teams in Google bother to change the clang-format behavior, indicating that most internal teams are either OK with or apathetic toward this style+ Would cause us to remove a "Chromium-specific" style rule from our guide+ Highly subjective: May make the "?" and ":" more obvious by aligning themNeutral:* Since the Google style guide is silent on the issue, I assume our decision either way is not as important as something that has an explicit Google style ruleIn short: Is one form more readable than the other? If not, do we choose consistency with the majority of existing code and historical practice, or consistency with Google style?Please opine.PK**Probably-lame regexes I used to measure:
--
--
Chromium Developers mailing list: chromi...@chromium.org
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-dev
--
--
Chromium Developers mailing list: chromi...@chromium.org
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-dev
--
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-dev...@chromium.org.
Also, my understanding is that this behavior is to follow the formatting of infix-dot, like Builder().Foo().Bar(). I strongly prefer those dot operators to be at the beginning, as clang-format does it now. I presume the dot-operator formatting is not a subject of this discussion.
--
I like ?: at the beginning. I think for the example here it doesn't really matter (though the example here should probably be on just one line). Maybe we should give some real, more complicated examples of what the formatting looks like.
I like ?: at the beginning. I think for the example here it doesn't really matter (though the example here should probably be on just one line). Maybe we should give some real, more complicated examples of what the formatting looks like.
In your suggestion first example (and in several of mine), the two cases are on the same line (but broken from the condition). I really prefer that when it fits, do we know if clang-format supports that?
After actually looking at a bunch of real example, the ?: at the beginning looks really bad to me in several cases. I think in some cases I prefer ?: at the beginning slightly more, but in others I greatly prefer ?: at the end.My vote would now be for ?: to go at the end.
I'm not sure if this is a screen width thing, but I see lines being wrapped (in the email) before the end of the line (based on line number):
Thread summary so far:* Break before: 6 votes (danakj, sgraham, dcheng, jyasskin, jamescook, rch)* Break after: 4 votes (pkasting, rsleevi, tsepez, chopman)Interestingly, no one has opined on things like "consistency with Google style" or "consistency with Chromium style" or in general anything other than "I like way X better". This makes it somewhat hard for me to decide what to do if the vote ends up being reasonably even. It would be nice to hear which of these principles people think should govern. For example, Nico has opined outside this thread that he thinks "consistency with Google style" should trump everything, while I've suggested that "Chromium codebase and style guide say X" is more important than anything else.
After all, if everyone thinks X is better than Y, we could just do X. But if people think that we should hew to <some other principle> unless all other things are equal, then that principle can guide us when the preferred style isn't broadly agreed-upon.
--
In Google C++ code (outside of Chromium), breaking after ?: is slightly more common, but not dramatically so.' (\?) *$' 57%'^ *(\?) ' 43%Since the Google style guide is silent on the issue, "consistency" dictates that Chromium should be silent on it also.
On Fri, Dec 19, 2014 at 6:00 PM, Steve Kobes <sko...@chromium.org> wrote:In Google C++ code (outside of Chromium), breaking after ?: is slightly more common, but not dramatically so.' (\?) *$' 57%'^ *(\?) ' 43%Since the Google style guide is silent on the issue, "consistency" dictates that Chromium should be silent on it also.(FWIW, here's an explicit "here's why clang-format does what it does" FAQ entry at https://goto.google.com/ternary (internal-only link, sorry) that's been ok'd by the style arbiters. So it's not an omission by accident.)
On Dec 19, 2014 4:52 PM, "'Peter Kasting' via Chromium-dev" <chromi...@chromium.org> wrote:
>
> Thread summary so far:
>
> * Break before: 6 votes (danakj, sgraham, dcheng, jyasskin, jamescook, rch)
> * Break after: 4 votes (pkasting, rsleevi, tsepez, chopman)
>
> Interestingly, no one has opined on things like "consistency with Google style" or "consistency with Chromium style" or in general anything other than "I like way X better". This makes it somewhat hard for me to decide what to do if the vote ends up being reasonably even. It would be nice to hear which of these principles people think should govern. For example, Nico has opined outside this thread that he thinks "consistency with Google style" should trump everything, while I've suggested that "Chromium codebase and style guide say X" is more important than anything else.
I found the "consistency with other operators" and "consistency with google code" to have approximately equal value, and don't put as much value on the rest. That left me not feeling strongly in either direction, so I just commented on my personal preference.
>
> After all, if everyone thinks X is better than Y, we could just do X. But if people think that we should hew to <some other principle> unless all other things are equal, then that principle can guide us when the preferred style isn't broadly agreed-upon.
>
> PK
>
On Dec 22, 2014 8:29 AM, "Devlin Cronin" <rdevlin...@chromium.org> wrote:
>
> FWIW, my preference is for 1) (breaking after the ternary). I don't think it's massively more readable either way, but I'd like to be consistent with the style that we've had (and still have in the majority of code). Further, this isn't a C++-only style, and I know it's come up before in, e.g., JS reviews. Since we can't just take the "do git cl format and forget about it" approach with all code, it seems strange to decide to move away from the status quo when there isn't (in my opinion) a truly concrete reason to do so.
I think "this is how most google code is formatted" is pretty concrete?
On Dec 22, 2014 8:29 AM, "Devlin Cronin" <rdevlin...@chromium.org> wrote:
>
> FWIW, my preference is for 1) (breaking after the ternary). I don't think it's massively more readable either way, but I'd like to be consistent with the style that we've had (and still have in the majority of code). Further, this isn't a C++-only style, and I know it's come up before in, e.g., JS reviews. Since we can't just take the "do git cl format and forget about it" approach with all code, it seems strange to decide to move away from the status quo when there isn't (in my opinion) a truly concrete reason to do so.I think "this is how most google code is formatted" is pretty concrete?
FWIW, my preference is for 1) (breaking after the ternary). I don't think it's massively more readable either way, but I'd like to be consistent with the style that we've had (and still have in the majority of code). Further, this isn't a C++-only style, and I know it's come up before in, e.g., JS reviews. Since we can't just take the "do git cl format and forget about it" approach with all code
, it seems strange to decide to move away from the status quo when there isn't (in my opinion) a truly concrete reason to do so.
--
I think it's worth pointing out that there's already for the dot operator, the arrow operator (this one is a bit contentious IIRC), and <<.
--
A third option (the ? after the test expression w/o whitespace). Example:
int x = is_value_set? value : 0;
I've seen a lot of code, albeit outside Google, that formats this way.
--
A third option (the ? after the test expression w/o whitespace). Example:
int x = is_value_set? value : 0;
I've seen a lot of code, albeit outside Google, that formats this way.
A third option (the ? after the test expression w/o whitespace). Example:
int x = is_value_set? value : 0;
I've seen a lot of code, albeit outside Google, that formats this way.
--