Please fix or revert: [PATCH] checkpatch: add --strict tests for braces, comments and casts
This recent checkpatch commit, added in v3.4-rc1:
aad4f6149831 checkpatch: add --strict tests for braces, comments and casts
made the default checkpatch run complain about the following perfectly fine multi-line comment block:
+ rdp->qlen_lazy = 0;
+ rdp->qlen = 0;
+
+ /*
+ * Adopt all callbacks. The outgoing CPU was in no shape + * to advance them, so make them all go through a full + * grace period. + */
+ *receive_rdp->nxttail[RCU_NEXT_TAIL] = rdp->nxtlist;
With:
CHECK: Don't begin block comments with only a /* line, use /* comment...
#80: FILE: kernel/rcutree.c:1428:
+
+ /*
Which is an obviously bogus warning: the comment is perfectly fine and it has the form that Documentation/CodingStyle specifically recommends:
| Chapter 8: Commenting | | [...] | | The preferred style for long (multi-line) comments is: | | /* | * This is the preferred style for multi-line | * comments in the Linux kernel source code. | * Please use it consistently. | * | * Description: A column of asterisks on the left side, | * with beginning and ending almost-blank lines. | */ |
Please turn this new warning off by default, or fix the check, or revert it. (The revert below applies cleanly on top of latest -git and solves the warning for me.)
Thanks,
Ingo
This reverts commit aad4f61498314d41d047ea2161b7bd7237b72d33.
--- scripts/checkpatch.pl | 40 ++++++++-------------------------------- 1 files changed, 8 insertions(+), 32 deletions(-)
scripts/checkpatch.pl +8 -32
@@ -1864,17 +1864,6 @@ sub process { } } - if ($line =~ /^\+.*\*[ \t]*\)[ \t]+/) { - CHK("SPACING", - "No space is necessary after a cast\n" . $hereprev); - } - - if ($rawline =~ /^\+[ \t]*\/\*[ \t]*$/ && - $prevrawline =~ /^\+[ \t]*$/) { - CHK("BLOCK_COMMENT_STYLE", - "Don't begin block comments with only a /* line, use /* comment...\n" . $hereprev); - } - # check for spaces at the beginning of a line. # Exceptions: # 1) within comments
@@ -2987,8 +2976,7 @@ sub process { #print "chunks<$#chunks> linenr<$linenr> endln<$endln> level<$level>\n"; #print "APW: <<$chunks[1][0]>><<$chunks[1][1]>>\n"; if ($#chunks > 0 && $level == 0) { - my @allowed = (); - my $allow = 0; + my $allowed = 0; my $seen = 0; my $herectx = $here . "\n"; my $ln = $linenr - 1;
@@ -2999,7 +2987,6 @@ sub process { my ($whitespace) = ($cond =~ /^((?:\s*\n[+-])*\s*)/s); my $offset = statement_rawlines($whitespace) - 1; - $allowed[$allow] = 0; #print "COND<$cond> whitespace<$whitespace> offset<$offset>\n"; # We have looked at and allowed this specific line.
@@ -3012,34 +2999,23 @@ sub process { $seen++ if ($block =~ /^\s*{/); - #print "cond<$cond> block<$block> allowed<$allowed[$allow]>\n"; + #print "cond<$cond> block<$block> allowed<$allowed>\n"; if (statement_lines($cond) > 1) { #print "APW: ALLOWED: cond<$cond>\n"; - $allowed[$allow] = 1; + $allowed = 1; } if ($block =~/\b(?:if|for|while)\b/) { #print "APW: ALLOWED: block<$block>\n"; - $allowed[$allow] = 1; + $allowed = 1; } if (statement_block_size($block) > 1) { #print "APW: ALLOWED: lines block<$block>\n"; - $allowed[$allow] = 1; + $allowed = 1; } - $allow++; } - if ($seen) { - my $sum_allowed = 0; - foreach (@allowed) { - $sum_allowed += $_; - } - if ($sum_allowed == 0) { - WARN("BRACES", - "braces {} are not necessary for any arm of this statement\n" . $herectx); - } elsif ($sum_allowed != $allow && - $seen != $allow) { - CHK("BRACES", - "braces {} should be used on all arms of this statement\n" . $herectx); - } + if ($seen && !$allowed) { + WARN("BRACES", + "braces {} are not necessary for any arm of this statement\n" . $herectx); } } }
Randy Dunlap
Acked-byQuoted 50 lines · Ingo Molnar
This recent checkpatch commit, added in v3.4-rc1:
aad4f6149831checkpatch: add --strict tests for braces, comments and castsmade the default checkpatch run complain about the following perfectly fine multi-line comment block:
(quoted diff) +9
-0+ rdp->qlen_lazy = 0; + rdp->qlen = 0; + + /* + * Adopt all callbacks. The outgoing CPU was in no shape + * to advance them, so make them all go through a full + * grace period. + */ + *receive_rdp->nxttail[RCU_NEXT_TAIL] = rdp->nxtlist;With:
CHECK: Don't begin block comments with only a /* line, use /* comment...
#80: FILE:
kernel/rcutree.c:1428:(quoted diff) +2
-0+ + /*Which is an obviously bogus warning: the comment is perfectly fine and it has the form that
Documentation/CodingStylespecifically recommends:| Chapter 8: Commenting | | [...] | | The preferred style for long (multi-line) comments is: | | /* | * This is the preferred style for multi-line | * comments in the Linux kernel source code. | * Please use it consistently. | * | * Description: A column of asterisks on the left side, | * with beginning and ending almost-blank lines. | */ |Please turn this new warning off by default, or fix the check, or revert it. (The revert below applies cleanly on top of latest -git and solves the warning for me.)
Quoted 7 lines
Thanks,
Ingo
This reverts commit
aad4f61498314d41d047ea2161b7bd7237b72d33.Signed-off-by Ingo Molnar <[email protected]>
Thanks.
Quoted 87 lines
--- scripts/checkpatch.pl | 40 ++++++++-------------------------------- 1 files changed, 8 insertions(+), 32 deletions(-)scripts/checkpatch.pl +8
-33@@ -1864,17 +1864,6 @@ sub process { } } - if ($line =~ /^\+.*\*[ \t]*\)[ \t]+/) { - CHK("SPACING", - "No space is necessary after a cast\n" . $hereprev); - } - - if ($rawline =~ /^\+[ \t]*\/\*[ \t]*$/ && - $prevrawline =~ /^\+[ \t]*$/) { - CHK("BLOCK_COMMENT_STYLE", - "Don't begin block comments with only a /* line, use /* comment...\n" . $hereprev); - } - # check for spaces at the beginning of a line. # Exceptions: # 1) within comments@@ -2987,8 +2976,7 @@ sub process { #print "chunks<$#chunks> linenr<$linenr> endln<$endln> level<$level>\n"; #print "APW: <<$chunks[1][0]>><<$chunks[1][1]>>\n"; if ($#chunks > 0 && $level == 0) { - my @allowed = (); - my $allow = 0; + my $allowed = 0; my $seen = 0; my $herectx = $here . "\n"; my $ln = $linenr - 1;@@ -2999,7 +2987,6 @@ sub process { my ($whitespace) = ($cond =~ /^((?:\s*\n[+-])*\s*)/s); my $offset = statement_rawlines($whitespace) - 1; - $allowed[$allow] = 0; #print "COND<$cond> whitespace<$whitespace> offset<$offset>\n"; # We have looked at and allowed this specific line.@@ -3012,34 +2999,23 @@ sub process { $seen++ if ($block =~ /^\s*{/); - #print "cond<$cond> block<$block> allowed<$allowed[$allow]>\n"; + #print "cond<$cond> block<$block> allowed<$allowed>\n"; if (statement_lines($cond) > 1) { #print "APW: ALLOWED: cond<$cond>\n"; - $allowed[$allow] = 1; + $allowed = 1; } if ($block =~/\b(?:if|for|while)\b/) { #print "APW: ALLOWED: block<$block>\n"; - $allowed[$allow] = 1; + $allowed = 1; } if (statement_block_size($block) > 1) { #print "APW: ALLOWED: lines block<$block>\n"; - $allowed[$allow] = 1; + $allowed = 1; } - $allow++; } - if ($seen) { - my $sum_allowed = 0; - foreach (@allowed) { - $sum_allowed += $_; - } - if ($sum_allowed == 0) { - WARN("BRACES", - "braces {} are not necessary for any arm of this statement\n" . $herectx); - } elsif ($sum_allowed != $allow && - $seen != $allow) { - CHK("BRACES", - "braces {} should be used on all arms of this statement\n" . $herectx); - } + if ($seen && !$allowed) { + WARN("BRACES", + "braces {} are not necessary for any arm of this statement\n" . $herectx); } } } --
Signature · 1 line
~Randy
Joe Perches
maintainerPATCH 1/1 checkpatch: revert --strict test for net/ and drivers/net block comment style
---
Quoted 4 lines · Randy Dunlap
Quoted 3 lines · Ingo Molnar
aad4f6149831checkpatch: add --strict tests for braces, comments and casts
made the default checkpatch run complain about the following perfectly fine multi-line comment block:
No, it didn't.
It only made checkpatch complain if --strict was
added to the command line arguments.
I don't care about the comment style, it is/was David Miller's preferred style for drivers/net and net/
I think a straight revert isn't appropriate.
Here's one that just removes the comment check.
Joe Perches
maintainerPATCH 1/1 checkpatch: revert --strict test for net/ and drivers/net block comment style
In reply to Randy DunlapRevert the --strict test for the old preferred block comment style in drivers/net and net/
---
grumble. Don't reply to email from internet cafes.
Quoted 4 lines · Randy Dunlap
Quoted 3 lines · Ingo Molnar
aad4f6149831checkpatch: add --strict tests for braces, comments and casts
made the default checkpatch run complain about the following perfectly fine multi-line comment block:
No, it didn't.
It only made checkpatch complain if --strict was added to the command line arguments.
I don't care about the comment style, it is/was David Miller's preferred style for drivers/net and net/
I think a straight revert isn't appropriate.
Here's one that just removes the comment check.
scripts/checkpatch.pl | 6 ------ 1 files changed, 0 insertions(+), 6 deletions(-)
scripts/checkpatch.pl +0 -6
@@ -1869,12 +1869,6 @@ sub process { "No space is necessary after a cast\n" . $hereprev); } - if ($rawline =~ /^\+[ \t]*\/\*[ \t]*$/ && - $prevrawline =~ /^\+[ \t]*$/) { - CHK("BLOCK_COMMENT_STYLE", - "Don't begin block comments with only a /* line, use /* comment...\n" . $hereprev); - } - # check for spaces at the beginning of a line. # Exceptions: # 1) within comments
Re: [PATCH] checkpatch: revert --strict test for net/ and drivers/net block comment style
Quoted 2 lines · Joe Perches
Revert the --strict test for the old preferred block comment style in
drivers/netandnet/
Emphatic NAK.
Thanks,
Ingo
Re: [PATCH] checkpatch: revert --strict test for net/ and drivers/net block comment style
Quoted 7 lines · Ingo Molnar
Quoted 2 lines · Joe Perches
Revert the --strict test for the old preferred block comment style in
drivers/netandnet/Emphatic NAK.
Ingo, I don't think you understood. That test reverts the thing you wanted reverted wrt the block comments.
It does not revert the *other* things in that patch (testing for empty braces etc).
So Joe's patch seems to be exactly what you asked for,
Linus
Ingo Molnar
Acked-byRe: [PATCH] checkpatch: revert --strict test for net/ and drivers/net block comment style
Quoted 11 lines · Linus Torvalds
Quoted 7 lines · Ingo Molnar
Quoted 2 lines · Joe Perches
Revert the --strict test for the old preferred block comment style in
drivers/netandnet/Emphatic NAK.
Ingo, I don't think you understood. That test reverts the thing you wanted reverted wrt the block comments.
Yeah, I was confused: I judged it by the title and description and assumed it was only doing it for drivers/net/ and net/.
But in reality it just does a wholesale revert of this check with no net/ and drivers/net/ specificity to it, so it's perfectly fine to me:
Thanks,
Ingo
Joe Perches
maintainerRe: [PATCH] checkpatch: revert --strict test for net/ and drivers/net block comment style
Quoted 2 lines · Ingo Molnar
Yeah, I was confused: I judged it by the title and description and assumed it was only doing it for
drivers/net/andnet/.
If you don't read the text, no amount of
geometric layout symmetry will clarify it.
From: Ingo Molnar <[email protected]>
Date: Mon, 16 Apr 2012 11:17:20 +0200
Quoted 9 lines
This recent checkpatch commit, added in v3.4-rc1:
aad4f6149831checkpatch: add --strict tests for braces, comments and castsmade the default checkpatch run complain about the following perfectly fine multi-line comment block:
Review
Quoted 9 lines
(quoted diff) +9
-0+ rdp->qlen_lazy = 0; + rdp->qlen = 0; + + /* + * Adopt all callbacks. The outgoing CPU was in no shape + * to advance them, so make them all go through a full + * grace period. + */ + *receive_rdp->nxttail[RCU_NEXT_TAIL] = rdp->nxtlist;
I would like to formally propose that we change CodingStyle so that our comments are of the form:
/* XXX * YYY */
So that we can save one line of vertical space.
We've adopted this all across the networking, and the code looks a lot nicer as well as allowing more actual code onto a single window of text.
Quoted 9 lines · David Miller
I would like to formally propose that we change CodingStyle so that our comments are of the form:
/* XXX
* YYY
*/So that we can save one line of vertical space.
Ugh, I personally hate it. No way will we make that the recommended version, even if it might be an acceptable substitute in some subsystems.
It looks unbalanced. If you want to save that vertical space, just use C++ style comments instead, for chissake! Then you save *two* lines, without the unbalanced thing, and just write it as
// XXX
// YYYwhich is much preferred.
Your suggested format just sucks, and has the worst of all worlds.
Linus
From: Linus Torvalds <[email protected]>
Date: Mon, 16 Apr 2012 12:09:12 -0700
Quoted 8 lines
It looks unbalanced. If you want to save that vertical space, just use C++ style comments instead, for chissake! Then you save *two* lines, without the unbalanced thing, and just write it as
// XXX // YYYwhich is much preferred.
I'm perfectly fine with this too.
Quoted 29 lines · David Miller
From: Ingo Molnar <[email protected]>
Date: Mon, 16 Apr 2012 11:17:20 +0200Quoted 9 lines
This recent checkpatch commit, added in v3.4-rc1:
aad4f6149831checkpatch: add --strict tests for braces, comments and castsmade the default checkpatch run complain about the following perfectly fine multi-line comment block:
Review
Quoted 9 lines
(quoted diff) +9
-0+ rdp->qlen_lazy = 0; + rdp->qlen = 0; + + /* + * Adopt all callbacks. The outgoing CPU was in no shape + * to advance them, so make them all go through a full + * grace period. + */ + *receive_rdp->nxttail[RCU_NEXT_TAIL] = rdp->nxtlist;I would like to formally propose that we change CodingStyle so that our comments are of the form:
/* XXX * YYY */
Quoted 5 lines
So that we can save one line of vertical space.
We've adopted this all across the networking, and the code looks a lot nicer as well as allowing more actual code onto a single window of text.
Sigh, this is sad for two reasons:
1) It's butt ugly and it violates every basic principle of typography. Saving a line is often counter-productive, a well placed whitespace (vertical or horizontal) will often increase readability. Key is good balance.
If you don't "see" it as ugly it's simply because your brain is not wired up to see 3D/2D geometry as a significant source of information. A significant portion (I'd guesstimate a narrow majority) of kernel hackers *does* see 2D/3D layout details in code and finds inconsistencies in them counterproductive.
( It's roughly the same distinction that makes some people
love the typographic layout of the iPhone/iPad while others consider it unnecessary bling. )
2) Even if it was proper typography (which it isnt), we have Documentation/CodingStyle for damn good reasons: so that people see a uniform style of code across the kernel. The taste set out there is sometimes arbitrary in its details, but one thing is certainly worse than arbitrary style rules:
*random*, inconsistent rules, because that only adds noise.
Thanks,
Ingo
Quoted 10 lines · Ingo Molnar
If you don't "see" it as ugly it's simply because your brain is not wired up to see 3D/2D geometry as a significant source of information. A significant portion (I'd guesstimate a narrow majority) of kernel hackers *does* see 2D/3D layout details in code and finds inconsistencies in them counterproductive.
( It's roughly the same distinction that makes some people
love the typographic layout of the iPhone/iPad while others consider it unnecessary bling. )
Another example are the recent Google+ layout changes. Those who don't see 2D details found it an unnecessary waste of screen real estate.
To me and many others the new layout, while sparser, is actually noticeably less taxing to read, because information is structured in such a "geometrically obvious" way.
Thanks,
Ingo
From: Ingo Molnar <[email protected]>
Date: Mon, 16 Apr 2012 22:34:51 +0200
Quoted 14 lines · Ingo Molnar
Quoted 11 lines
If you don't "see" it as ugly it's simply because your brain is not wired up to see 3D/2D geometry as a significant source of information. A significant portion (I'd guesstimate a narrow majority) of kernel hackers *does* see 2D/3D layout details in code and finds inconsistencies in them counterproductive.
( It's roughly the same distinction that makes some people
love the typographic layout of the iPhone/iPad while others consider it unnecessary bling. )
Quoted 7 lines
Another example are the recent Google+ layout changes. Those who don't see 2D details found it an unnecessary waste of screen real estate.
To me and many others the new layout, while sparser, is actually noticeably less taxing to read, because information is structured in such a "geometrically obvious" way.
I guess us visual retards will have to find a new web site to use then, thanks for the lesson Ingo.
Quoted 3 lines · David Miller
I guess us visual retards will have to find a new web site to use then, thanks for the lesson Ingo.
Facebook would love to welcome you back :-)
I must be retarded, as I still find facebook better than G+.
-- Steve
Quoted 21 lines · David Miller
From: Ingo Molnar <[email protected]>
Date: Mon, 16 Apr 2012 22:34:51 +0200Quoted 18 lines · Ingo Molnar
Quoted 11 lines
If you don't "see" it as ugly it's simply because your brain is not wired up to see 3D/2D geometry as a significant source of information. A significant portion (I'd guesstimate a narrow majority) of kernel hackers *does* see 2D/3D layout details in code and finds inconsistencies in them counterproductive.
( It's roughly the same distinction that makes some people
love the typographic layout of the iPhone/iPad while others consider it unnecessary bling. )Another example are the recent Google+ layout changes. Those who don't see 2D details found it an unnecessary waste of screen real estate.
Quoted 6 lines
Quoted 3 lines
To me and many others the new layout, while sparser, is actually noticeably less taxing to read, because information is structured in such a "geometrically obvious" way.
I guess us visual retards will have to find a new web site to use then, thanks for the lesson Ingo.
All I'm trying to point out is that it's a visual conflict that exists which probably has genetic origins.
For you it's too much whitespace, for me (and apparently Linus) the lack of it results in harder to read patterns of code due to missing geometric symmetry clues.
Since I don't have your brain and your eyes I cannot know exactly how bad the extra whitespaces are for you - and you probably don't know how bad the lack of symmetry is for me and others.
So I did not intend to make any judgement about it one way or another, but I guessed that a bit more vertical size is probably less taxing than less structure - but I'm obviously biased. If it's really bad for you we can still reconsider.
( I suspect it would be pretty hard but not impossible to
construct an objective readability test to settle similar issues scientifically and create an 'ideal' coding style based on objective rules alone, eliminating subjective 'taste'. )
Thanks,
Ingo
Joe Perches
maintainerQuoted 4 lines · Ingo Molnar
1) It's butt ugly and it violates every basic principle of typography. Saving a line is often counter-productive, a well placed whitespace (vertical or horizontal) will often increase readability. Key is good balance.
True enough.
Quoted 6 lines
If you don't "see" it as ugly it's simply because your brain is not wired up to see 3D/2D geometry as a significant source of information. A significant portion (I'd guesstimate a narrow majority) of kernel hackers *does* see 2D/3D layout details in code and finds inconsistencies in them counterproductive.
I believe there's an empty hat somewhere that must have produced this email.
I rather doubt anyone "sees" 3d geometries out of
a coding style. Otherwise, cite please...
From: Ingo Molnar <[email protected]>
Date: Mon, 16 Apr 2012 22:26:54 +0200
Quoted 3 lines
If you don't "see" it as ugly it's simply because your brain is not wired up to see 3D/2D geometry as a significant source of information.
I'm sorry that I'm so handicapped that I cannot match your visual capabilitites.
I hope you have a nice day too Ingo.
(Sorry about the late reply, was busy with other things.)
Quoted 9 lines · David Miller
From: Ingo Molnar <[email protected]>
Date: Mon, 16 Apr 2012 22:26:54 +0200Quoted 3 lines
If you don't "see" it as ugly it's simply because your brain is not wired up to see 3D/2D geometry as a significant source of information.
I'm sorry that I'm so handicapped that I cannot match your visual capabilitites.
I genuinely think that it's the other way around: if what I say above is true then *you* have the superior vision for coding.
Geometric properties of code are a distraction really, they don't matter to the end result.
So in reality keeping comments balanced helps *my* disability:
my inability to ignore functionally irrelevant patterns of characters...
So I am asking *you* to do me a favor: please understand my perspective and insert a bit more whitespace to keep code readable for people like me.
( The wider question is, what is the contribution weighted
proportion of the two groups of kernel developers and what is the disutility and utility of the two variants. It's a difficult balancing task and there's no perfect solution. )
Thanks,
Ingo