digitalmars.D - "Good PR" mechanical check
- Andrei Alexandrescu (20/20) Jan 12 2016 Related to https://github.com/D-Programming-Language/dlang.org/pull/1191...
- =?UTF-8?Q?Martin_Dra=c5=a1ar?= via Digitalmars-d (9/36) Jan 12 2016 o
- Andrei Alexandrescu (3/5) Jan 12 2016 That would suffice at least in the beginning. We also need to put dfmt
- H. S. Teoh via Digitalmars-d (29/36) Jan 12 2016 In principle, I agree with mechanical checking of formatting (instead of
- Brian Schott (18/40) Jan 12 2016 It will. There's a solution in the form of special comments:
- H. S. Teoh via Digitalmars-d (10/34) Jan 13 2016 [...]
- Andrei Alexandrescu (3/16) Jan 13 2016 BTW I recall it was your code containing a "switch(x){" that prompted
- H. S. Teoh via Digitalmars-d (5/23) Jan 13 2016 Haha, was it? I don't recall anymore. :-P
- Rikki Cattermole (3/23) Jan 12 2016 dfmt + create patch compared to before and after format.
- Adam D. Ruppe (6/9) Jan 12 2016 I'm not sure if git supports this but I think it should be done
- w0rp (3/3) Jan 12 2016 I think using dfmt for this is a good idea. If there any problems
- Walter Bright (2/3) Jan 12 2016 The last 1% always takes 99% of the dev time :-(
- John Colvin (5/8) Jan 12 2016 But in this case, the 1% doesn't actually have to be fixed
- Jacob Carlborg (7/10) Jan 12 2016 The hook/tool would need to do a commit with the changes. How would what...
- Sebastiaan Koppe (7/18) Jan 12 2016 Yeah, don't know how that can be made to work.
- tsbockman (8/9) Jan 12 2016 I realize that dfmt may need some upgrades first, but isn't it
- rsw0x (7/16) Jan 12 2016 Doubt I'm alone in that I'd be more willing to contribute if
- Andrei Alexandrescu (3/9) Jan 12 2016 I would support that. We need a strong champion there. Brian wanted to
- Mathias Lang (10/32) Jan 12 2016 There is already an attempt to it in DMD:
Related to https://github.com/D-Programming-Language/dlang.org/pull/1191: A friend who is in the GNU community told me a while ago they have a mechanical style checker that people can run against their proposed patches to make sure the patches have a style consistent with the one enforced by the GNU style. I forgot the name, something like "good-patch". I'll shoot him an email. Similarly, I think it would help us to release a tool in the tools/ repo that analyzes a would-be Phobos pull request and ensures it's styled the same way as most of Phobos: braces on their own lines, whitespace inserted a specific way, no hard tabs, etc. etc. Then people can run the tool before even submitting a PR to make sure there's no problem of that kind. Over the years I've developed some adaptability to style, and I can do Phobos' style no problem even though it wouldn't be my first preference (I favor Egyptian braces). But seeing a patchwork of styles within the same project, same file, and sometimes even the same pull request is quite jarring at least to me. Who would like to embark on writing such a tool? Thanks, Andrei
Jan 12 2016
Dne 12.1.2016 v 14:34 Andrei Alexandrescu via Digitalmars-d napsal(a):Related to https://github.com/D-Programming-Language/dlang.org/pull/119=1:=20 A friend who is in the GNU community told me a while ago they have a mechanical style checker that people can run against their proposed patches to make sure the patches have a style consistent with the one enforced by the GNU style. I forgot the name, something like "good-patch". I'll shoot him an email. =20 Similarly, I think it would help us to release a tool in the tools/ rep=othat analyzes a would-be Phobos pull request and ensures it's styled th=esame way as most of Phobos: braces on their own lines, whitespace inserted a specific way, no hard tabs, etc. etc. Then people can run th=etool before even submitting a PR to make sure there's no problem of tha=tkind. =20 Over the years I've developed some adaptability to style, and I can do Phobos' style no problem even though it wouldn't be my first preference=(I favor Egyptian braces). But seeing a patchwork of styles within the same project, same file, and sometimes even the same pull request is quite jarring at least to me. =20 Who would like to embark on writing such a tool? =20 =20 Thanks, =20 AndreiWouldn't it be sufficient to mandate usage of dfmt with proper settings before submitting a PR? Martin
Jan 12 2016
On 01/12/2016 08:42 AM, Martin Drašar via Digitalmars-d wrote:Wouldn't it be sufficient to mandate usage of dfmt with proper settings before submitting a PR?That would suffice at least in the beginning. We also need to put dfmt in tools, again a project that's been in limbo for a long time. -- Andrei
Jan 12 2016
On Tue, Jan 12, 2016 at 02:03:57PM -0500, Andrei Alexandrescu via Digitalmars-d wrote:On 01/12/2016 08:42 AM, Martin Drašar via Digitalmars-d wrote:In principle, I agree with mechanical checking of formatting (instead of the endless tedious nitpicking over the fine points of Phobos style), but, as Jonathan has brought up before, there are cases where human judgment is required and a tool would probably make a big mess of things. For example, certain unittests in std.datetime where customized formatting of array literals are used to make it easier to read the test cases, such as `testGregDaysBC` in std/datetime.d, as well as the several array literals inside the same unittest block. This is just one of many examples one can find in std.datetime. There are also some (smaller) examples in std.range, such as in transposed(), where nested arrays are formatted like matrices in order to make it clear what the function is trying to do. I'm almost certain dfmt (or any mechanical formatting tool) will completely ruin this. These formatting exceptions are primarily semantically-motivated; as such I don't expect a mechanical tool to be able to figure it out automatically. (E.g., nested arrays in transposed() may need 2D formatting, but in byChunk() it makes more sense to format them linearly with line-wrapping.) I propose that a better approach is to automate dfmt (or whatever tool) to check PRs and highlight places where the formatting deviates from the mechanical interpretation of the rules, so that submitters can have their attention brought to potentially problematic points, and reviewers don't have to scrutinize every line, but only look at the places that may require some human judgment to decide on. T -- "640K ought to be enough" -- Bill G. (allegedly), 1984. "The Internet is not a primary goal for PC usage" -- Bill G., 1995. "Linux has no impact on Microsoft's strategy" -- Bill G., 1999.Wouldn't it be sufficient to mandate usage of dfmt with proper settings before submitting a PR?That would suffice at least in the beginning. We also need to put dfmt in tools, again a project that's been in limbo for a long time. -- Andrei
Jan 12 2016
On Wednesday, 13 January 2016 at 05:19:36 UTC, H. S. Teoh wrote:There are also some (smaller) examples in std.range, such as in transposed(), where nested arrays are formatted like matrices in order to make it clear what the function is trying to do. I'm almost certain dfmt (or any mechanical formatting tool) will completely ruin this.It will. There's a solution in the form of special comments: // dfmt off auto treeStructure = [ node(0, 0), node(1, 0), node(2, 0), node(10, 2), node(3, 0) ]; // dfmt on // dfmt off stuff.map!(a => complicatedFunction(a, 100) * 20) .filter!(a => a < 2_000 && a %3 == 0) .sum(); // dfmt onThese formatting exceptions are primarily semantically-motivated; as such I don't expect a mechanical tool to be able to figure it out automatically. (E.g., nested arrays in transposed() may need 2D formatting, but in byChunk() it makes more sense to format them linearly with line-wrapping.)Correct.I propose that a better approach is to automate dfmt (or whatever tool) to check PRs and highlight places where the formatting deviates from the mechanical interpretation of the rules, so that submitters can have their attention brought to potentially problematic points, and reviewers don't have to scrutinize every line, but only look at the places that may require some human judgment to decide on.This might work.
Jan 12 2016
On Wed, Jan 13, 2016 at 07:53:45AM +0000, Brian Schott via Digitalmars-d wrote:On Wednesday, 13 January 2016 at 05:19:36 UTC, H. S. Teoh wrote:[...] Fair enough, but will this work in ddoc'd unittests, where you don't necessarily want those dfmt comments to make it into the generated docs? But, case in point, won't UFCS chains be poorly formatted in general? Or are there dfmt comments that can switch dfmt to "UFCS mode"? Or does it detect UFCS chains and format accordingly? T -- To err is human; to forgive is not our policy. -- Samuel AdlerThere are also some (smaller) examples in std.range, such as in transposed(), where nested arrays are formatted like matrices in order to make it clear what the function is trying to do. I'm almost certain dfmt (or any mechanical formatting tool) will completely ruin this.It will. There's a solution in the form of special comments: // dfmt off auto treeStructure = [ node(0, 0), node(1, 0), node(2, 0), node(10, 2), node(3, 0) ]; // dfmt on // dfmt off stuff.map!(a => complicatedFunction(a, 100) * 20) .filter!(a => a < 2_000 && a %3 == 0) .sum(); // dfmt on
Jan 13 2016
On 1/13/16 12:19 AM, H. S. Teoh via Digitalmars-d wrote:On Tue, Jan 12, 2016 at 02:03:57PM -0500, Andrei Alexandrescu via Digitalmars-d wrote:BTW I recall it was your code containing a "switch(x){" that prompted this idea :o). True story. -- AndreiOn 01/12/2016 08:42 AM, Martin Drašar via Digitalmars-d wrote:In principle, I agree with mechanical checking of formatting (instead of the endless tedious nitpicking over the fine points of Phobos style), but, as Jonathan has brought up before, there are cases where human judgment is required and a tool would probably make a big mess of things.Wouldn't it be sufficient to mandate usage of dfmt with proper settings before submitting a PR?That would suffice at least in the beginning. We also need to put dfmt in tools, again a project that's been in limbo for a long time. -- Andrei
Jan 13 2016
On Wed, Jan 13, 2016 at 08:47:19AM -0500, Andrei Alexandrescu via Digitalmars-d wrote:On 1/13/16 12:19 AM, H. S. Teoh via Digitalmars-d wrote:Haha, was it? I don't recall anymore. :-P T -- Не дорог подарок, дорога любовь.On Tue, Jan 12, 2016 at 02:03:57PM -0500, Andrei Alexandrescu via Digitalmars-d wrote:BTW I recall it was your code containing a "switch(x){" that prompted this idea :o). True story. -- AndreiOn 01/12/2016 08:42 AM, Martin Drašar via Digitalmars-d wrote:In principle, I agree with mechanical checking of formatting (instead of the endless tedious nitpicking over the fine points of Phobos style), but, as Jonathan has brought up before, there are cases where human judgment is required and a tool would probably make a big mess of things.Wouldn't it be sufficient to mandate usage of dfmt with proper settings before submitting a PR?That would suffice at least in the beginning. We also need to put dfmt in tools, again a project that's been in limbo for a long time. -- Andrei
Jan 13 2016
On 13/01/16 2:34 AM, Andrei Alexandrescu wrote:Related to https://github.com/D-Programming-Language/dlang.org/pull/1191: A friend who is in the GNU community told me a while ago they have a mechanical style checker that people can run against their proposed patches to make sure the patches have a style consistent with the one enforced by the GNU style. I forgot the name, something like "good-patch". I'll shoot him an email. Similarly, I think it would help us to release a tool in the tools/ repo that analyzes a would-be Phobos pull request and ensures it's styled the same way as most of Phobos: braces on their own lines, whitespace inserted a specific way, no hard tabs, etc. etc. Then people can run the tool before even submitting a PR to make sure there's no problem of that kind. Over the years I've developed some adaptability to style, and I can do Phobos' style no problem even though it wouldn't be my first preference (I favor Egyptian braces). But seeing a patchwork of styles within the same project, same file, and sometimes even the same pull request is quite jarring at least to me. Who would like to embark on writing such a tool? Thanks, Andreidfmt + create patch compared to before and after format. No need for a whole new tool.
Jan 12 2016
On Tuesday, 12 January 2016 at 13:34:25 UTC, Andrei Alexandrescu wrote:Similarly, I think it would help us to release a tool in the tools/ repo that analyzes a would-be Phobos pull request and ensures it's styled the same way as most of PhobosI'm not sure if git supports this but I think it should be done fully automatically. Not even something the user runs, just when they open the pull request, it reformats the code. I'm pretty sure dfmt is up to the task in 99% of cases already.
Jan 12 2016
I think using dfmt for this is a good idea. If there any problems with dfmt which would prevent it from being used on Phobos, the problems can be patched and then that would strengthen dfmt.
Jan 12 2016
On 1/12/2016 6:53 AM, Adam D. Ruppe wrote:I'm pretty sure dfmt is up to the task in 99% of cases already.The last 1% always takes 99% of the dev time :-(
Jan 12 2016
On Tuesday, 12 January 2016 at 17:22:16 UTC, Walter Bright wrote:On 1/12/2016 6:53 AM, Adam D. Ruppe wrote:But in this case, the 1% doesn't actually have to be fixed (although of course, the smaller the better), it's just the 1% of the work left to be done manually, where currently we do 100% manually.I'm pretty sure dfmt is up to the task in 99% of cases already.The last 1% always takes 99% of the dev time :-(
Jan 12 2016
On 2016-01-12 15:53, Adam D. Ruppe wrote:I'm not sure if git supports this but I think it should be done fully automatically. Not even something the user runs, just when they open the pull request, it reformats the code.The hook/tool would need to do a commit with the changes. How would what work? The tool wouldn't have commit access to the repository from where the PR originates. It would also create a new commit hash that wouldn't match with what the user have locally. -- /Jacob Carlborg
Jan 12 2016
On Tuesday, 12 January 2016 at 21:04:33 UTC, Jacob Carlborg wrote:On 2016-01-12 15:53, Adam D. Ruppe wrote:Yeah, don't know how that can be made to work. The closest I got was https://help.github.com/articles/about-webhooks/ at least then you can check whether dfmt agrees with the pull request (and block it) But people still need to manually run the thing.I'm not sure if git supports this but I think it should be done fully automatically. Not even something the user runs, just when they open the pull request, it reformats the code.The hook/tool would need to do a commit with the changes. How would what work? The tool wouldn't have commit access to the repository from where the PR originates. It would also create a new commit hash that wouldn't match with what the user have locally.
Jan 12 2016
On Tuesday, 12 January 2016 at 13:34:25 UTC, Andrei Alexandrescu wrote:[...]I realize that dfmt may need some upgrades first, but isn't it about time to just suck it up and dfmt the whole of phobos and druntime? It will mess with the "git blame", true - but it will do so *once* and end tedious manual inspection of formatting for pull requests forever.
Jan 12 2016
On Tuesday, 12 January 2016 at 18:25:48 UTC, tsbockman wrote:On Tuesday, 12 January 2016 at 13:34:25 UTC, Andrei Alexandrescu wrote:Doubt I'm alone in that I'd be more willing to contribute if phobos and druntime used dfmt. I personally use a style near the complete opposite of phobos/druntime (2 spaces per indent, OTBS etc.) It's a chore to have to scrutinize every line to make sure it matches the style guide instead of just running it through a tool.[...]I realize that dfmt may need some upgrades first, but isn't it about time to just suck it up and dfmt the whole of phobos and druntime? It will mess with the "git blame", true - but it will do so *once* and end tedious manual inspection of formatting for pull requests forever.
Jan 12 2016
On 01/12/2016 01:25 PM, tsbockman wrote:On Tuesday, 12 January 2016 at 13:34:25 UTC, Andrei Alexandrescu wrote:I would support that. We need a strong champion there. Brian wanted to get to it for a long time, but didn't muster the time. -- Andrei[...]I realize that dfmt may need some upgrades first, but isn't it about time to just suck it up and dfmt the whole of phobos and druntime? It will mess with the "git blame", true - but it will do so *once* and end tedious manual inspection of formatting for pull requests forever.
Jan 12 2016
On Tuesday, 12 January 2016 at 13:34:25 UTC, Andrei Alexandrescu wrote:Related to https://github.com/D-Programming-Language/dlang.org/pull/1191: A friend who is in the GNU community told me a while ago they have a mechanical style checker that people can run against their proposed patches to make sure the patches have a style consistent with the one enforced by the GNU style. I forgot the name, something like "good-patch". I'll shoot him an email. Similarly, I think it would help us to release a tool in the tools/ repo that analyzes a would-be Phobos pull request and ensures it's styled the same way as most of Phobos: braces on their own lines, whitespace inserted a specific way, no hard tabs, etc. etc. Then people can run the tool before even submitting a PR to make sure there's no problem of that kind. Over the years I've developed some adaptability to style, and I can do Phobos' style no problem even though it wouldn't be my first preference (I favor Egyptian braces). But seeing a patchwork of styles within the same project, same file, and sometimes even the same pull request is quite jarring at least to me. Who would like to embark on writing such a tool? Thanks, AndreiThere is already an attempt to it in DMD: https://github.com/D-Programming-Language/dmd/blob/master/src/checkwhitespace.d Agree it would be useful to have a tool which needs to be part of the auto-tester (I think it's called from the Makefile for DMD). We could also provide a `post-commit-hook` that people can use so git checks it automatically. It needs to be checked on a per-commit basis because else we'll end up with commits affecting each other, which is no good either.
Jan 12 2016