Update .clang-format to match version 4.0.0.#881
Update .clang-format to match version 4.0.0.#881ahmedcharles merged 1 commit intoMudlet:developmentfrom ahmedcharles:clang-format
Conversation
|
What're the thoughts on Google C++ Style Guide? I don't have strong personal opinions on the style guide we use just as long as we can settle on something fast and future contributors wouldn't find it a problem, so I'm looking at pre-existing ones that carry some weight that we could adopt |
|
I can't find anything good to say about the Google C++ Style Guide. There are two somewhat dated books but they get the fundamentals right: https://www.amazon.com/Exceptional-Style-Engineering-Programming-Solutions/dp/0201760428/ref=asap_bc?ie=UTF8 Granted, I think they only have 2-3 pages on things like what clang-format does, because the authors just say that you should be consistent and move on. The clang-format settings that we have are my attempt at matching what the code currently does, though I that's not my personal preference. I'd prefer not to step on other people's preferences just because I have different ones. :) |
|
In any case, this is just a starting point. I'd like to start running clang-format and making PR's with various changes and see what people think. The code is currently inconsistent, which is probably the worse of all worlds. |
|
OK, that's fine, it's out of the window then. |
src/.clang-format
Outdated
| - Regex: '.*' | ||
| Priority: 1 | ||
| IncludeIsMainRegex: '$' | ||
| SortIncludes: false # revisit |
There was a problem hiding this comment.
This would be nice to have, but I think it breaks those guards doesn't it
There was a problem hiding this comment.
I turned it off because I need to configure the priorities and see if I can make the guards work.
|
👎 I can't make use of clang-format 4.0... |
|
Yeah it's a bit problematic for me as well: Shouldn't be a blocker though, the tool is out and available - I'll see what I can do. @SlySven check out http://llvm.org/releases/download.html (when it's up). |
|
It should work with previous versions, with the exception of 1-2 fields perhaps, which have changed from being boolean to being an enumeration. I just downloaded it earlier from that link, so I'm somewhat surprised it went down right after. What version do you both have access to? |
|
I see that that download site has a Debian 8 (Jessie) clang download as a pre-built binary - but I realise I am using "Jessie-backports" so I can get 3.8 versions if I explictly ask for them with |
|
Same for me, 3.8 is what I've got installed OK. @ahmedcharles mentioned there are static 4.0 binaries available - but if it's just a few fields and nothing major, let's stay on 3.8? |
|
Yeah, we want to use tools that other will also be able to use to format their contributions. So that means putting a hold on this PR? |
|
Sure. Can you just try running |
|
The only error message it spams is |
|
Um, I'd rather not do an in-place edit ( |
|
You can remove the As for the memory usage, that's abnormal, since I just ran the exact same commands. You can just remove the 'IncludeIsMainRegex' from the file and see if that helps? |
|
It was trying to format |
|
@SlySven how'd you get default fields in constructor to align? Did you use |
|
@SlySven To be honest now that we'll have a formatting tool in place, I don't think we have to require braces around single-line blocks, because the problem solves itself: no braces is only an issue if you don't get your indenting right, but now we can, very easily. |
|
That's not entirely true, because it's unlikely that clang-format will end up being used to format the entire code-base, unconditionally. There's some code that will just look better manually formatted. Besides, characters that can be seen |
|
With the fact that we will now get lines like |
|
Okay!
I'm aiming to approve this tonight - Stephen could you as well?
…On Fri, 14 Apr 2017 12:51 am Stephen Lyons, ***@***.***> wrote:
With the fact that we now get } else { I'd like to see braces being used
everywhere (at least until I get used to the change - and those visible
delimiters do help. I recently sent in a small patch to the Input team for
the Linux Kernel and their "style" allows single line un-braced if/else
branches only if BOTH branches are 1 liners - but that is not sommat I'd
normally want to do myself.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#881 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAGxjD2ER8V5B4VVFwvYyTCoybg3gQvfks5rvqb3gaJpZM4M8IAN>
.
|
vadi2
left a comment
There was a problem hiding this comment.
Not interested in bikeshedding over this so I'll keep it short and sweet - ColumnLimit 200 is making me scroll sideways on 1900x1080 resolution, and if I turn on word wrapping in my editor, then things get even uglier - if we turn it down to something around 100 I'll approve.
Can live with the rest and happy with 90% of the changes, so thanks a ton for looking into this again 👍
|
The comment that says to revisit it is there because it won't be 200 forever. It's just a starting point. I'm not even changing that in this commit, so why would that block updating everything else? The expected use case for clang-format is making a commit and then running: This means that for the fairly short time I'm actively making formatting changes, you would never have to actually scroll your editor, because it would never edit code while you were editing it. Though my primary point is: PR's can't be expected to fix every bug and the existence of a bug in the file doesn't warrant preventing other changes to the file. |
vadi2
left a comment
There was a problem hiding this comment.
Yeah I certainly agree with your primary point, you should not be expected to fix other issues you haven't touched in a PR.
|
I still don't get the proposed workflow however - why not get the formatting done right once, so we can apply it and continue with the new way once and for all, instead of iterating on it and littering git blame history with continuious reformatting? |
| AccessModifierOffset: -4 | ||
| ConstructorInitializerIndentWidth: 4 | ||
| ContinuationIndentWidth: 4 | ||
| ConstructorInitializerIndentWidth: 0 |
There was a problem hiding this comment.
Yeah, I spotted them being dragged to the right when we applied the "existing" file to XMLimport class a few weeks ago, and I was requested to refrain from adjusting the previous settings in this file in #372. *looks across to another member of the team* 😉
There was a problem hiding this comment.
Actually in that PR was commit: c7e21b6 where I had some revisions which got subsequently backed out again but one of them was a ColumnLimit:120 - down from the prior 200... and a few settings that we had not set/(changed from defaults?)
There was a problem hiding this comment.
The exact problem was that a PR that changing how the XML files are read in has nothing to do with changing .clang-format settings - a separate PR with the right scope would have been fine but was never attempted.
|
I would like us to have an agreed formatting setup that we can just hammer out/configure once and then can be used any-time from the QtCreator beautify menu. I am prepared to accept that some of my styling wishes, like the hanging indent I use on "[ TYPE ] - message to be shown on main console" - so that:
won't survive being tidied. Is it worth commenting in the .clang-format file those settings that do not work before 4.0 or have different behaviour between 3.8 and 4.0 I have just found that QtCreator's handling of the clang-format tool allows some predefined selections besides the "File" option to use the dot file in the current or ancestor directory. In addition there is an internal system to name your own style and then you can (copy and) paste in your own recipe and it seems to recognise most settings and attempts to document the possible options, but not much else: |
|
I'm not sure about the confusion, given that I gave the exact commands above. I know that workflow works and due to the fact that it uses I'm a git power user, so I prefer using rebase/amend/squash/etc to make commits look like what I want, rather than just making commit after commit which will mess up the history of the project. As far as I can tell, the current concerns are all related to workflow and potential lack of knowledge rather than strictly being opposed to what I'm proposing, at least in this commit. Hit me up on gitter if you want to talk about it. |
|
The exact confusion is more about how the process will work - I'm lost between PRs that are formatting entire files (good) and comments saying that this is just a starting point for the settings (confusing - if this is not the final version, it implies we'll be reformatting them again). Sorry for being difficult on this. |
|
Oh, ok. The changes I submit are from me running clang-format and then I run Basically, I'm looking at and deciding on every change whether it should go or not, that's how I'm making sure that this process converges. |
|
Okay, that makes sense. What can we tell new contributors to do in the future then to make sure their changes are formatted right? I suppose ask them to selectively format the parts of the files they've changed instead of running the formatter on the entire file? The former would be a lot more simple, but it would break custom formatting we have. My perfect state on this is that we have all the rules encoded within clang-format so it's the canonical source of truth on this and we can just press a button and it'll spit out a result we'll be happy with, seems the easiest way to do these things. |
|
The most flexible workflow that I know of is this: clang-format's editor integration normally supports formatting selections and formatting individual lines, so that shouldn't be a huge issue. Unfortunately, C++ is really complicated in terms of syntax and I don't really know if we have lots of common places where we'll want to not format things the way clang-format does. There are a few cases of The mental model for formatting Go, for example, is like you suggest. You just press the button and the outcome is fine. But Go was designed with that in mind, C++ wasn't and C++ has some weird corners. I'm just taking the conservative position that 100% automatic formatting may not be optimal and we may want to avoid certain sections. clang-format was designed with this in mind and therefore, makes it easy to achieve that result. |
|
Alright, fair enough, we'll live with it and just ask contributors to selectively format stuff - plus the git commands for the power users. |
src/.clang-format
Outdated
| AfterClass: false | ||
| AfterControlStatement: false | ||
| AfterEnum: false | ||
| AfterFunction: false |
There was a problem hiding this comment.
Following discussion on Gitter, and testing its effects, this is one that I would like to have set `true.
src/.clang-format
Outdated
| BreakBeforeBinaryOperators: true | ||
| BreakBeforeBraces: Linux | ||
| BraceWrapping: | ||
| AfterClass: false |
There was a problem hiding this comment.
After the older comment below - this too is something I would like to be true.
There was a problem hiding this comment.
I assume AfterStruct and AfterUnion you also want to be true? What about AfterEnum?
| BreakBeforeBraces: Linux | ||
| BraceWrapping: | ||
| AfterClass: false | ||
| AfterControlStatement: false |
There was a problem hiding this comment.
I believe this to be so that the '{' for an if (...) { is moved to the next line if true - so I am happy with false here.
| PenaltyReturnTypeOnItsOwnLine: 60 | ||
|
|
||
| # includes | ||
| IncludeCategories: |
There was a problem hiding this comment.
I am not familiar with this but I am presuming this is a different way to try and position the pre/post_guard.h files to avoid the hard-wired "turn clang-format off" around them that I previously tried. 👍 if it works.
There was a problem hiding this comment.
It works. That change already happened and got merged.
| # comments | ||
| # CommentPragmas: | ||
| CommentPragmas: '' | ||
| ReflowComments: false # revisit |
There was a problem hiding this comment.
I agree that it may be useful to revisit this one, especially with a reasonable value for "line width" or what ever the "right margin" setting is - can't see it right know.
| BraceWrapping: | ||
| AfterClass: false | ||
| AfterControlStatement: false | ||
| AfterEnum: false |
There was a problem hiding this comment.
Despite the inconsistency the one case (where I used) it is used seems OK with false.
There are settings for 4.0, but they are commented out currently.
src/.clang-format
Outdated
| AfterEnum: false | ||
| AfterFunction: false | ||
| AfterNamespace: false | ||
| AfterStruct: false |
There was a problem hiding this comment.
true matches more closely what we have been using and discussions have suggested to me that keeping it the same as class is not unreasonable.
There was a problem hiding this comment.
struct and class are the same except for the default accessibility of the members in the definition.
| AfterFunction: false | ||
| AfterNamespace: false | ||
| AfterStruct: false | ||
| AfterUnion: false |
There was a problem hiding this comment.
We do not use union so is not yet relevant.
SlySven
left a comment
There was a problem hiding this comment.
I reserve the right to moan about a setting that I didn't understand what it would do, not being "right" here later. 😀



No description provided.