--
--
Chromium Developers mailing list: chromi...@chromium.org
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-dev
--
--
--
Thiago
Is ClangFormat stable yet? There's still been regular churn about
cleaning up edge cases
Going back to stability - using which version of clang-format? Thepinned version? Does this mean that as clang-format changes its layout
flow, users will have to reformat files to match the latest behaviours
and/or bugs?
This also will create a huge amount of diff churn - and perhaps
ongoing. This has been a general sore point for any format discussions
cleanup (for example, cleanups of method/typename ordering to match
what the style guide advises)
What about Windows - where clang-format can parse the AST, but we'venever run binaries with it.
This also seems like it can introduce real debt (the loss of blameclarity and the ongoing chasing of the latest format whims). Are the
current costs worth it?
clang-format formats the code in _a_ way that is consistent with our style guidelines, but there are many other acceptable ways, and in several cases that I've seen, they're preferable (at least to me).
I recommend using a special "refactor" role account for that, though - to make it easier to spot places where you have to go back an extra step in blame, and so you don't get accused of using this as an underhanded way to get to the top of the leaderboard :)
Sure, but this would require even more steps. I think the benefit of
this reformatting is tiny, whereas the cost of slower git blame is
big. I really don't like the proposal.
--
On Tue, Apr 30, 2013 at 4:14 PM, Avi Drissman <a...@chromium.org> wrote:
clang-format formats the code in _a_ way that is consistent with our style guidelines, but there are many other acceptable ways, and in several cases that I've seen, they're preferable (at least to me).Well, but I think this is missing the bigger picture. Isn't is more important that we're consistent (and I mean mechanically consistent) across the entire codebase than it is to have your pet style nit go your way in the code you often edit, and my way in mine?
This is because I am strongly opinionated about what I find readable in ways that go well beyond what the style guide specifies. (My opinion could not possibly be more different from Rachel's "If I cared where and on what line things were, I'd write poetry".)
What I want to get back is the hours spent finding, arguing about and fixing formatting problems, (and the time for newbies to learn it to the point where they don't get pummelled by it). I do git blame much less often than I submit or perform a code review, and with a role account doing the one-time change, we could even theoretically make a version of git-blame that skips those automatically and jumps to the previous version to find out the "real" blame for that line or lines.
The Google style guide intentionally does not cover a lot of things. As a readability reviewer I'm often in a position where I either recommend (but do not require) some change the style guide doesn't cover. It's reasonable for people to accept or reject these suggestions, and both happen.
Similarly, in Chromium, there are a lot of different conventions in different areas which are equally legal under the style guide. These don't differ at random; they differ because different people find different things to be more readable, useful, or consistent, sometimes significantly so.
I'm uncomfortable overriding this. I'm not convinced that the current state of the world is more costly than a world in which formatting was more consistent, but for some people on the team less readable in code that they own and work with every day.
I don't see much of a problem with your code following your pet style nit and my code following mine, whereas I have a big problem with my code _not_ following my pet style nit. This is because I am strongly opinionated about what I find readable in ways that go well beyond what the style guide specifies. (My opinion could not possibly be more different from Rachel's "If I cared where and on what line things were, I'd write poetry".) Out of respect for other people who feel just as strongly but differ on what they prefer, I'm not even comfortable with a hypothetical "well, what if we made it always do what _you_ want" formatter.
I would be OK with an "unopinionated" formatter that enforces the letter of the law and doesn't change a single thing outside that -- but I suspect such a thing would be difficult to write, and of course it would not generate the complete consistency that you see as the benefit of this change. It would, however, eliminate outright violations of the Google style guide, and at least reduce the number of cases where people need to reformat a style-related issue.
There is no way to ever get back the sunk time spent on formatting problems. You can only save that time going forward, which doesn't really require running clang-format over the entire codebase, only over things you're changing.
On Tue, Apr 30, 2013 at 4:57 PM, Greg Spencer <gspe...@google.com> wrote:
What I want to get back is the hours spent finding, arguing about and fixing formatting problems
[...]
There is no way to ever get back the sunk time spent on formatting problems. You can only save that time going forward, which doesn't really require running clang-format over the entire codebase, only over things you're changing.
WRT whether you personally run git blame more or less often than you personally make code-formatting decisions, that's not really relevant.
In my experience, when someone is running git-blame it's often because they're trying to fix something which was too subtle to figure out from just looking at the code. I think it's pretty reasonable to add some friction on the writing-new-code side in the interests of making it easier to figure out how things got to be the way they are, if only because if it's too hard to manage the latter, people will just give up (you are unlikely to simply give up on your CL just because someone wanted you to reformat a function call).
I think the only way clang-format can actually solve the problem with the time wasted on useless style discussions in code reviews is if it is run _automatically_ for _all_ new code.
Mostly I didn't mean that I think we should add friction to writing code specifically to make git-blame easier. Rather, I'm saying that IMHO it's not worth minor gains if the cost is that git-blame is harder. My reasoning is that decoding code evolution is already hard enough, to the point where people who are trying to do that are usually trying to do it because nothing else easier has worked. So if you make it harder, you're making exactly the wrong thing harder.
The [git|svn]-blame case is not impossible to solve. We could probably make clang-format spit out some kind of metadata when it does the format (i.e., a listing that maps the lines pre-format to the lines post-format, thus allowing "blame" information to be preserved), but I imagine we'd want to get a feature in git/svn that allowed us to ingest that metadata along with a "formatting-only" change, updating the "blame" in a one-off manner. I have absolutely no idea how that would be accomplished, but I imagine it is possible. Disclaimer: IAMNAE on source control. There are probably people on this list with the ability to comment on this, don't be shy... surely the topic of reformatting support is not unknown to the source control community.
As far as comparing the logical functionality of code across the formatting barrier, it seems clear that one could simply run clang-format on the old revision (and the new one) before doing the diff. I imagine that git and svn could also be patched to allow a kind of pre-diff filter that was specifically designed to accommodate formatting operations like this. If you ran the latest clang-format on both the old and new revisions, you'd magically steamroll over the need to care about which version of clang-format was used to format the given code - you'd just see a reasonable diff that showed the non-format-related work that had been done. So that's cool.
There is actually a kinda hilarious option that I'm sure we wouldn't want to do, but does exist: we could run clang-format on *every revision in history* and rewrite the whole of history to be formatted correctly forever. This might take a while, and we'd probably have to drop svn first. :)
Git actually supports diff filters that would handle this with no other work required; see "man gitattributes" and look for the filter option. No need to patch it.
There is actually a kinda hilarious option that I'm sure we wouldn't want to do, but does exist: we could run clang-format on *every revision in history* and rewrite the whole of history to be formatted correctly forever. This might take a while, and we'd probably have to drop svn first. :)Haha! Oh, that is bold. Well, I think we could do that, but we could actually even improve the usefulness of git blame without ever changing any code if we could add that diff pass to git blame that would normalize formatting in all the revisions of the file you're looking at locally before doing the diffs, as Andrew proposed. That would eliminate all existing format-only line changes from the history before doing the blame without actually changing any code, making the logic changes more prominent. We should make that possible even if we don't reformat all the current code, IMO.
Git actually supports diff filters that would handle this with no other work required; see "man gitattributes" and look for the filter option. No need to patch it.Sweet!-Greg.
Now that I think of it, another option (although I don't know how feasible it is) is to have a presubmit script that applies it only to *changed* lines (or adjacent lines if you changed a line that is split), immediately before sending a cl for review. It still gets rid of style discussions in the future, but doesn't screw with blame or require a huge refactor CL. It still might leave individual files inconsistent, but I'd argue that at this level, as long as it doesn't change indentation, the inconsistency will be largely irrelevant. I'm fine with any option, as long as I can opt into it, and out of making style decisions.
On Tue, Apr 30, 2013 at 4:57 PM, Greg Spencer <gspe...@google.com> wrote:
Sure, but this would require even more steps. I think the benefit of
this reformatting is tiny, whereas the cost of slower git blame is
big. I really don't like the proposal.Well, but it's not the readability benefit of the reformatting itself that I'm looking for here: I could really care less about that since most of the differences are nits.What I want to get back is the hours spent finding, arguing about and fixing formatting problems, (and the time for newbies to learn it to the point where they don't get pummelled by it). I do git blame much less often than I submit or perform a code review, and with a role account doing the one-time change, we could even theoretically make a version of git-blame that skips those automatically and jumps to the previous version to find out the "real" blame for that line or lines.-Greg.
I hear that you're strongly opinionated about what you find readable, but I contend that if everything were formatted the same way, you'd come to see that as the most readable form after a while.
Also, consider your own time: if you spend a lot of time formatting code to be "readable", or suggesting adjustments in code reviews to make sure it's readable, then you're wasting your time if a tool can reasonably do it for you, right?
In the end, this is about efficiency. Can you read other people's code now?
Both of those examples are legal Chromium style. If you want to argue that clang-format is doing the wrong thing here, you should first change the style guide.
On Wed, May 1, 2013 at 9:24 AM, Adrienne Walker <en...@chromium.org> wrote:Both of those examples are legal Chromium style. If you want to argue that clang-format is doing the wrong thing here, you should first change the style guide.No, they're not, per my reading of the Google style guide.The constructor list section at http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml?showone=Constructor_Initializer_Lists#Constructor_Initializer_Lists allows initializers all on one line only when that one line is also the line containing the rest of the function prototype.
The function definition section at http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml?showone=Function_Declarations_and_Definitions#Function_Declarations_and_Definitions gives no example of a function body all on one line. Examples in the style guide are normative.
The problem is that there are ten thousand issues like this where not everyone is coming at the problem with the same reading or style guide interpretation. Coming to agreement on these and encoding them in the formatter is going to take years.
But that's my argument. The style guide was (and is) a guide to formatting. clang-format is conformant to the style guide, but there are many valid choices that are not the ones that it's making, and in quite a few cases it's significantly uglier or less easy to read than the others.
I'm not sure that's a strong argument against using an automated formatter.
I think this shows a problem; it makes some sense to reformat code that doesn't meet the coding standard, but one often has good reasons for making formatting choices within the coding standard. For example, I, at least, often add a blank line between semantically distinct sections of code. This is not something that can easily be explained to a formatting tool. If clang_formatter is going to reformat everything then it will make code much less readable than code formatted by somebody who understands it.
On Wed, May 1, 2013 at 9:39 AM, Anthony Berent <abe...@chromium.org> wrote:I think this shows a problem; it makes some sense to reformat code that doesn't meet the coding standard, but one often has good reasons for making formatting choices within the coding standard. For example, I, at least, often add a blank line between semantically distinct sections of code. This is not something that can easily be explained to a formatting tool. If clang_formatter is going to reformat everything then it will make code much less readable than code formatted by somebody who understands it.Wait, would clang_formatter get rid of blank lines in the middle of functions? I could live with just about any other formatting decision, but this one would really bug me.
--
I don't think clang-format is ready yet:
[...]
We normally wrap each initialization in its own line, so it's easier
to read, but clang-format produces:
: key_code_(keycode), type_(ui::ET_KEY_PRESSED), modifiers_(modifiers) {}
So, no, I don't think clang-format will produce code easier to read,
at least not in its current shape.
On Tue, Apr 30, 2013 at 10:21 PM, Greg Spencer <gspe...@google.com> wrote:I actively enjoy reformatting my code until it feels perfect. This probably sounds perverse to most other people.
In the end, this is about efficiency. Can you read other people's code now?Not without annoyance.
--
Anything non-1TBS causes annoyance. (ducks) :-)The point, I guess, being that the two goals of a style guide are to improve readability and decrease arguments. I'd say we get a good grade on the former, but a pretty poor grade on the latter. If the style guide produced optimal results, then it might be a big concern to yield a little readability to get greatly decrease arguments.Since even our most enlightened and sensitive contributors don't feel that way, it seems to me like it'd be a big win to just obey the robot and save lots of argumentation for minimal (and reparable) readability harm.
On Tue, Apr 30, 2013 at 4:34 PM, Greg Spencer <gspe...@google.com> wrote:
On Tue, Apr 30, 2013 at 4:14 PM, Avi Drissman <a...@chromium.org> wrote:
clang-format formats the code in _a_ way that is consistent with our style guidelines, but there are many other acceptable ways, and in several cases that I've seen, they're preferable (at least to me).Well, but I think this is missing the bigger picture. Isn't is more important that we're consistent (and I mean mechanically consistent) across the entire codebase than it is to have your pet style nit go your way in the code you often edit, and my way in mine?IMO, no.The Google style guide intentionally does not cover a lot of things. As a readability reviewer I'm often in a position where I either recommend (but do not require) some change the style guide doesn't cover. It's reasonable for people to accept or reject these suggestions, and both happen.Similarly, in Chromium, there are a lot of different conventions in different areas which are equally legal under the style guide. These don't differ at random; they differ because different people find different things to be more readable, useful, or consistent, sometimes significantly so.I'm uncomfortable overriding this. I'm not convinced that the current state of the world is more costly than a world in which formatting was more consistent, but for some people on the team less readable in code that they own and work with every day. I don't see much of a problem with your code following your pet style nit and my code following mine, whereas I have a big problem with my code _not_ following my pet style nit. This is because I am strongly opinionated about what I find readable in ways that go well beyond what the style guide specifies. (My opinion could not possibly be more different from Rachel's "If I cared where and on what line things were, I'd write poetry".) Out of respect for other people who feel just as strongly but differ on what they prefer, I'm not even comfortable with a hypothetical "well, what if we made it always do what _you_ want" formatter.I would be OK with an "unopinionated" formatter that enforces the letter of the law and doesn't change a single thing outside that -- but I suspect such a thing would be difficult to write, and of course it would not generate the complete consistency that you see as the benefit of this change. It would, however, eliminate outright violations of the Google style guide, and at least reduce the number of cases where people need to reformat a style-related issue.
PK
For the record, I feel strongly against this. Peter and Mark expressed the reasons against this more eloquently than I would.I think we have much more important problems to solve.
On Wed, May 1, 2013 at 12:40 PM, John Abd-El-Malek <j...@chromium.org> wrote:
For the record, I feel strongly against this. Peter and Mark expressed the reasons against this more eloquently than I would.I think we have much more important problems to solve.I think the argument is we could more spend time solving these other important issues if auto-formatting saved us N man years of manually dealing with style nits
For the record, I feel strongly against this. Peter and Mark expressed the reasons against this more eloquently than I would.I think we have much more important problems to solve.
I haven't yet heard an argument from Peter, Mark, or anyone else that doesn't boil down to "because I like it my way"
You seem to be assuming that there’s no information being conveyed by distinguishing between alternative code constructions within the “permitted,” “tolerated,” and “not forbidden” space. I don’t think that’s true.
You’re simplifying this to the point that you’re arguing for saving time, money, or some other resource, believing that your proposal has no cost beyond an implementation and conversion effort. I think that there is a readability cost.
You’re allowed to disagree with my analysis, but framing my position and arguments as “because I like it my way” is insulting, as is dismissing them based on that flawed interpretation instead of considering their merits.
Possible compromise ideas:* Could we consider allowing submodules (i.e. anything at the directory level) to opt-in, and have our tooling enforce it at that level?
* Could we consider making it extremely easy to "opt-out" of auto-formatting for a single file, function, or even block? That would allow us some flexibility even in cases where we want to auto-format most of the code. It reminds me of "lint" and NOLINT annotations.
I'll be the obnoxious one to say +1 to your extremely well-stated summary re: the art and the skill of the author in communication with others. We should never let this be compromised.In a utopian world it may be possible but I am concerned we don't live in that world. And here's where I agree with John - rather than trying to build that world for this specific issue, I'd rather us as a team work on higher priority technical debt repayment.
Possible compromise ideas:* Could we consider allowing submodules (i.e. anything at the directory level) to opt-in, and have our tooling enforce it at that level?I actually think we have to do this anyhow, at least at the moment: Blink code follows a different style (WebKit style) than the rest of the code, so there's at least one directory that needs it.
* Could we consider making it extremely easy to "opt-out" of auto-formatting for a single file, function, or even block? That would allow us some flexibility even in cases where we want to auto-format most of the code. It reminds me of "lint" and NOLINT annotations.I'd really be against anything that requires us to annotate the code: that could only make it less readable and cluttered, and presubmit shouldn't be that invasive. Note that we already have a way of skipping presubmit checks. We could expand that to make it possible to just skip formatting checks.-Greg.
--
+1
This discussion wasn't for nothing though: I think that the idea to improve git blame by factoring out formatting changes between revisions still has some legs.
Maybe this has already been suggested, but my take is that if we had a tool that you could run over your CL that would just fix-up the lines you are already touching, then perhaps people might choose to use that. It might make them more efficient. If most people start using such a tool, then it might be worth considering turning it on by default (with an opt-out).
-Darin
--
Maybe this has already been suggested, but my take is that if we had a tool that you could run over your CL that would just fix-up the lines you are already touching, then perhaps people might choose to use that. It might make them more efficient. If most people start using such a tool, then it might be worth considering turning it on by default (with an opt-out).
Then it sounds like we are all set for now :-)
I'm certainly going to give it a try. Others could too. I don't think we need to make it run by default at this point.
Perhaps it would be good to wrap this as a script in depot_tools and do something to help people discover it.
-Darin
-Greg.
This is simpler (I think it's the same, but git is crazy):git diff @{u}And this might be better:git diff $(git merge-base HEAD @{u})
A suggestion, skip java files out of the diff for formatting purposes
since the formatting does not play well with those.
PSA: 'git cl format'https://codereview.chromium.org/14629012/ introduces a new command: 'git cl format'. If you develop Chromium using git, and use proper feature branches (i.e. branches explicitly tracking an upstream, usually master or origin/master), then you can use 'git cl format' to automatically pass your current diff through clang-format. In addition, you can use 'git cl format --full' to pass every .h, .cc, and .cpp file you've touched in the current CL through clang-format.
This tool is provided for developers who want to use clang-format on their own CLs. Use at your own discretion :)