Drop braces around single statement rule
PATCH 1/1 Drop braces around single statement rule
History has shown that this particular rule is unenforcable.
--- CODING_STYLE | 11 ++++++----- 1 files changed, 6 insertions(+), 5 deletions(-)
CODING_STYLE +6 -5
@@ -54,16 +54,17 @@ readers that they are seeing a wrapped version; otherwise avoid this prefix. 4. Block structure -Every indented statement is braced; even if the block contains just one -statement. The opening brace is on the line that contains the control -flow statement that introduces the new block; the closing brace is on the -same line as the else keyword, or on a line by itself if there is no else -keyword. Example: +The opening brace is on the line that contains the control flow +statement that introduces the new block; the closing brace is on the +same line as the else keyword, or on a line by itself if there is no +else keyword. Example: if (a == 5) { printf("a was 5.\n"); + do5stuff(); } else if (a == 6) { printf("a was 6.\n"); + do6stuff(); } else { printf("a was something else entirely.\n"); }
Signature · 1 line
1.6.6.1
Quoted 24 lines · malc
History has shown that this particular rule is unenforcable.
Signed-off-by malc <[email protected]>--- CODING_STYLE | 11 ++++++----- 1 files changed, 6 insertions(+), 5 deletions(-)CODING_STYLE +4
-5@@ -54,16 +54,17 @@ readers that they are seeing a wrapped version; otherwise avoid this prefix. 4. Block structure -Every indented statement is braced; even if the block contains just one -statement. The opening brace is on the line that contains the control -flow statement that introduces the new block; the closing brace is on the -same line as the else keyword, or on a line by itself if there is no else -keyword. Example: +The opening brace is on the line that contains the control flow +statement that introduces the new block; the closing brace is on the +same line as the else keyword, or on a line by itself if there is no +else keyword. Example:
CODING_STYLE readers that they are seeing a wrapped version; otherwise avoid this prefix. · line 70
Quoted 10 lines
CODING_STYLE +2
-0if (a == 5) { printf("a was 5.\n"); + do5stuff(); } else if (a == 6) { printf("a was 6.\n"); + do6stuff(); } else { printf("a was something else entirely.\n"); }
I am "neutral" on this particular rule.
OTOH, my opinion is that we really should try to enforce the rules. The fact that we are humans and make mistakes (some patches not enforcing all the rules are committed), is not enough to just ignore the rules. If a rule is not enforceable, it should be removed from CODING_STYLE, not removed.
Signature · 2 lines
Aurelien Jarno GPG: 1024D/F1BCDB73 [email protected] http://www.aurel32.net
Quoted 38 lines · Aurelien Jarno
Quoted 24 lines · malc
History has shown that this particular rule is unenforcable.
Signed-off-by malc <[email protected]>--- CODING_STYLE | 11 ++++++----- 1 files changed, 6 insertions(+), 5 deletions(-)CODING_STYLE +4
-5@@ -54,16 +54,17 @@ readers that they are seeing a wrapped version; otherwise avoid this prefix. 4. Block structure -Every indented statement is braced; even if the block contains just one -statement. The opening brace is on the line that contains the control -flow statement that introduces the new block; the closing brace is on the -same line as the else keyword, or on a line by itself if there is no else -keyword. Example: +The opening brace is on the line that contains the control flow +statement that introduces the new block; the closing brace is on the +same line as the else keyword, or on a line by itself if there is no +else keyword. Example:CODING_STYLE readers that they are seeing a wrapped version; otherwise avoid this prefix. · line 70
Quoted 10 lines
CODING_STYLE +2
-0if (a == 5) { printf("a was 5.\n"); + do5stuff(); } else if (a == 6) { printf("a was 6.\n"); + do6stuff(); } else { printf("a was something else entirely.\n"); }I am "neutral" on this particular rule.
Quoted 5 lines
OTOH, my opinion is that we really should try to enforce the rules. The fact that we are humans and make mistakes (some patches not enforcing all the rules are committed), is not enough to just ignore the rules. If a rule is not enforceable, it should be removed from
CODING_STYLE, not removed.
^^^^^^^
Oops, you should read "ignored" here.
Signature · 2 lines
Aurelien Jarno GPG: 1024D/F1BCDB73 [email protected] http://www.aurel32.net
Quoted 6 lines · malc
History has shown that this particular rule is unenforcable.
Signed-off-by malc <[email protected]>---
CODING_STYLE | 11 ++++++-----1 files changed, 6 insertions(+), 5 deletions(-)
Not again:
http://lists.nongnu.org/archive/html/qemu-devel/2009-12/msg00484.html
There are plenty of ways to make the rule enforceable, for example we could agree to start to revert commits which introduce new CODING_STYLE violations.
Quoted 10 lines · Blue Swirl
Quoted 6 lines · malc
History has shown that this particular rule is unenforcable.
Signed-off-by malc <[email protected]>---
CODING_STYLE | 11 ++++++-----1 files changed, 6 insertions(+), 5 deletions(-)Not again:
http://lists.nongnu.org/archive/html/qemu-devel/2009-12/msg00484.html
I'm not yet senile enough to forget that, let me quote some:
"By picking a single coding style we've pretty much guaranteed that most people will disagree with some of it. IMO consistency is more important."
We don't have consistency, people, myself included (which was a suprise), keep applying patches that break things in this particular regard, it should just go.
Quoted 5 lines
There are plenty of ways to make the rule enforceable, for example we could agree to start to revert commits which introduce new
CODING_STYLEviolations.
There might be plenty of ways, but none were/are used, we somehow managed to enforce tab rule, but the braces remain elusive.
Signature · 1 line
mailto:[email protected]
Quoted 8 lines · Blue Swirl
Quoted 6 lines · malc
History has shown that this particular rule is unenforcable.
Signed-off-by malc <[email protected]>---
CODING_STYLE | 11 ++++++-----1 files changed, 6 insertions(+), 5 deletions(-)
Quoted 7 lines
Not again:
http://lists.nongnu.org/archive/html/qemu-devel/2009-12/msg00484.htmlThere are plenty of ways to make the rule enforceable, for example we could agree to start to revert commits which introduce new
CODING_STYLEviolations.
It seems to be possible to add a pre-applypatch script to the git hook directory, that will verify the commit and reject it if it doesn't comply with the coding rules. Of course it's possible to commit a patch anyway by using --no-verify.
The good point of this approach is that the rule is enforced by a script, which is not suppose to make mistakes, and that it can be shared between patch submitters and patch committers: both side can make mistakes and it is always better to know that as early as possible.
Of course someone as to translate the coding rules in a set of regular expressions able to catch errors.
Signature · 2 lines
Aurelien Jarno GPG: 1024D/F1BCDB73 [email protected] http://www.aurel32.net
Quoted 19 lines · Aurelien Jarno
Quoted 9 lines · Blue Swirl
Quoted 7 lines · malc
History has shown that this particular rule is unenforcable.
Signed-off-by malc<[email protected]>--- CODING_STYLE | 11 ++++++----- 1 files changed, 6 insertions(+), 5 deletions(-)Quoted 8 lines
Not again:
http://lists.nongnu.org/archive/html/qemu-devel/2009-12/msg00484.htmlThere are plenty of ways to make the rule enforceable, for example we could agree to start to revert commits which introduce new
CODING_STYLEviolations.
Quoted 5 lines
It seems to be possible to add a pre-applypatch script to the git hook directory, that will verify the commit and reject it if it doesn't comply with the coding rules. Of course it's possible to commit a patch anyway by using --no-verify.
There are certain aspects of CODING_STYLE that I think are pretty important. For instance, space vs. tabs can really screw things up for people that have non-standard tabs. This is something that enforcing at patch submission time seems to be really important.
Type naming seems important too because it's often not isolated. IOW, a poor choice in one file can end up polluting other files quickly that require interacting. The result is a mess of naming styles.
But something like braces around an if doesn't seem like it creates a big problem. Most C programmers are used to seeing braces in some statements and not other. Therefore, it's hard to argue that the code gets really unreadable if this isn't strictly enforced.
So really, I think the problem is that we're enforcing the words of CODING_STYLE instead of the intent. The intent of CODING_STYLE is to improve the readability of the code. I think it requires a certain amount of taste to be applied.
Rejecting a big patch because braces aren't used in single line if statements seems to be an unnecessary barrier to me.
Regards,
Anthony Liguori
Quoted 9 lines
The good point of this approach is that the rule is enforced by a script, which is not suppose to make mistakes, and that it can be shared between patch submitters and patch committers: both side can make mistakes and it is always better to know that as early as possible.
Of course someone as to translate the coding rules in a set of regular expressions able to catch errors.
Am 02.08.2010 17:20, schrieb Anthony Liguori:
Quoted 31 lines · Aurelien Jarno
Quoted 19 lines · Blue Swirl
Quoted 10 lines · malc
Quoted 8 lines
History has shown that this particular rule is unenforcable.
Signed-off-by malc<[email protected]>--- CODING_STYLE | 11 ++++++----- 1 files changed, 6 insertions(+), 5 deletions(-)Quoted 8 lines
Not again:
http://lists.nongnu.org/archive/html/qemu-devel/2009-12/msg00484.htmlThere are plenty of ways to make the rule enforceable, for example we could agree to start to revert commits which introduce new
CODING_STYLEviolations.Quoted 5 lines
It seems to be possible to add a pre-applypatch script to the git hook directory, that will verify the commit and reject it if it doesn't comply with the coding rules. Of course it's possible to commit a patch anyway by using --no-verify.
There are certain aspects of
CODING_STYLEthat I think are pretty important. For instance, space vs. tabs can really screw things up for people that have non-standard tabs. This is something that enforcing at patch submission time seems to be really important.
Quoted 8 lines
Type naming seems important too because it's often not isolated. IOW, a poor choice in one file can end up polluting other files quickly that require interacting. The result is a mess of naming styles.
But something like braces around an if doesn't seem like it creates a big problem. Most C programmers are used to seeing braces in some statements and not other. Therefore, it's hard to argue that the code gets really unreadable if this isn't strictly enforced.
I won't argue that missing braces impact readability of the code, they probably don't. However, as was pointed out in earlier discussion there still remain two important points:
1. While it doesn't make a difference for the code itself, readability of patches suffers when braces have to be added/removed when a second line is inserted or disappears.
2. I've messed up more than once with adding some debug code (even worse when it happens with real code):
if (foo)
fprintf(stderr, "debug msg\n");
bar(); /* oops, not conditional any more */This is why I tend to disagree with removing the rule, and suggest to rather implement some automatic checks like Aurelien suggested (if we need to change anything at all). I usually don't ask for a respin just for braces if the patch is good otherwise, but if you think we should just reject such patches without exceptions, I can change that.
Quoted 7 lines
So really, I think the problem is that we're enforcing the words of
CODING_STYLEinstead of the intent. The intent ofCODING_STYLEis to improve the readability of the code. I think it requires a certain amount of taste to be applied.Rejecting a big patch because braces aren't used in single line if statements seems to be an unnecessary barrier to me.
Taking such patches anyway is basically what we're doing today, right? And what malc is complaining about.
Kevin
Quoted 6 lines · Kevin Wolf
Quoted 6 lines
But something like braces around an if doesn't seem like it creates a big problem. Most C programmers are used to seeing braces in some statements and not other. Therefore, it's hard to argue that the code gets really unreadable if this isn't strictly enforced.
Quoted 8 lines
I won't argue that missing braces impact readability of the code, they probably don't. However, as was pointed out in earlier discussion there still remain two important points:
1. While it doesn't make a difference for the code itself, readability of patches suffers when braces have to be added/removed when a second line is inserted or disappears.
I understand the argument but it's not something that I strongly agree with.
Quoted 7 lines
2. I've messed up more than once with adding some debug code (even worse when it happens with real code):
if (foo)
fprintf(stderr, "debug msg\n"); bar(); /* oops, not conditional any more */
This is hard to do with editors that auto indent unless you're copying and pasting debugging. And yeah, I've made that mistake too doing the later :-)
Quoted 6 lines
This is why I tend to disagree with removing the rule, and suggest to rather implement some automatic checks like Aurelien suggested (if we need to change anything at all). I usually don't ask for a respin just for braces if the patch is good otherwise, but if you think we should just reject such patches without exceptions, I can change that.
Yeah, I try to remember to enforce it but often forget or just don't notice. My eyes don't tend to catch missing braces like they would catch bad type naming because the former is really not uncommon.
I'm happy with the status quo but I won't object to a git commit hook that enforces style.
Regards,
Anthony Liguori
Quoted 36 lines · Anthony Liguori
Quoted 6 lines · Kevin Wolf
Quoted 6 lines
But something like braces around an if doesn't seem like it creates a big problem. Most C programmers are used to seeing braces in some statements and not other. Therefore, it's hard to argue that the code gets really unreadable if this isn't strictly enforced.
Quoted 8 lines
I won't argue that missing braces impact readability of the code, they probably don't. However, as was pointed out in earlier discussion there still remain two important points:
1. While it doesn't make a difference for the code itself, readability of patches suffers when braces have to be added/removed when a second line is inserted or disappears.
I understand the argument but it's not something that I strongly agree with.
Quoted 7 lines
2. I've messed up more than once with adding some debug code (even worse when it happens with real code):
if (foo)
fprintf(stderr, "debug msg\n"); bar(); /* oops, not conditional any more */This is hard to do with editors that auto indent unless you're copying and pasting debugging. And yeah, I've made that mistake too doing the later :-)
Quoted 6 lines
This is why I tend to disagree with removing the rule, and suggest to rather implement some automatic checks like Aurelien suggested (if we need to change anything at all). I usually don't ask for a respin just for braces if the patch is good otherwise, but if you think we should just reject such patches without exceptions, I can change that.
Quoted 6 lines
Yeah, I try to remember to enforce it but often forget or just don't notice. My eyes don't tend to catch missing braces like they would catch bad type naming because the former is really not uncommon.
I'm happy with the status quo but I won't object to a git commit hook that enforces style.
Seriously? You are happy with the situation where some people get their patches rejected because they disagree/forogot/don't_care about single statement braces while the patches of others make it through?
Signature · 1 line
mailto:[email protected]
Quoted 47 lines · malc
Quoted 44 lines · Anthony Liguori
Quoted 7 lines · Kevin Wolf
Quoted 7 lines
But something like braces around an if doesn't seem like it creates a big problem. Most C programmers are used to seeing braces in some statements and not other. Therefore, it's hard to argue that the code gets really unreadable if this isn't strictly enforced.
Quoted 9 lines
I won't argue that missing braces impact readability of the code, they probably don't. However, as was pointed out in earlier discussion there still remain two important points:
1. While it doesn't make a difference for the code itself, readability of patches suffers when braces have to be added/removed when a second line is inserted or disappears.
I understand the argument but it's not something that I strongly agree with.
Quoted 8 lines
2. I've messed up more than once with adding some debug code (even worse when it happens with real code):
if (foo)
fprintf(stderr, "debug msg\n"); bar(); /* oops, not conditional any more */This is hard to do with editors that auto indent unless you're copying and pasting debugging. And yeah, I've made that mistake too doing the later :-)
Quoted 7 lines
This is why I tend to disagree with removing the rule, and suggest to rather implement some automatic checks like Aurelien suggested (if we need to change anything at all). I usually don't ask for a respin just for braces if the patch is good otherwise, but if you think we should just reject such patches without exceptions, I can change that.
Yeah, I try to remember to enforce it but often forget or just don't notice. My eyes don't tend to catch missing braces like they would catch bad type naming because the former is really not uncommon.
Quoted 7 lines
Quoted 3 lines
I'm happy with the status quo but I won't object to a git commit hook that enforces style.
Seriously? You are happy with the situation where some people get their patches rejected because they disagree/forogot/don't_care about single statement braces while the patches of others make it through?
Yeah, I'm neglecting the fact that we're not consistent as maintainers and I'm all for dropping it from CODING_STYLE.
Regards,
Anthony Liguori
Quoted 67 lines · Anthony Liguori
Quoted 66 lines · malc
Quoted 61 lines · Anthony Liguori
Quoted 10 lines · Kevin Wolf
Quoted 9 lines
But something like braces around an if doesn't seem like it creates a big problem. Most C programmers are used to seeing braces in some statements and not other. Therefore, it's hard to argue that the code gets really unreadable if this isn't strictly enforced.
Quoted 9 lines
I won't argue that missing braces impact readability of the code, they probably don't. However, as was pointed out in earlier discussion there still remain two important points:
1. While it doesn't make a difference for the code itself, readability of patches suffers when braces have to be added/removed when a second line is inserted or disappears.
I understand the argument but it's not something that I strongly agree with.
Quoted 9 lines
2. I've messed up more than once with adding some debug code (even worse when it happens with real code):
if (foo)
fprintf(stderr, "debug msg\n");
bar(); /* oops, not conditional any more */This is hard to do with editors that auto indent unless you're copying and
pasting debugging. And yeah, I've made that mistake too doing the later :-)Quoted 8 lines
This is why I tend to disagree with removing the rule, and suggest to rather implement some automatic checks like Aurelien suggested (if we need to change anything at all). I usually don't ask for a respin just for braces if the patch is good otherwise, but if you think we should just reject such patches without exceptions, I can change that.
Yeah, I try to remember to enforce it but often forget or just don't notice.
My eyes don't tend to catch missing braces like they would catch bad type naming because the former is really not uncommon.I'm happy with the status quo but I won't object to a git commit hook that
enforces style.
Quoted 7 lines
Quoted 4 lines
Seriously? You are happy with the situation where some people get their patches rejected because they disagree/forogot/don't_care about single statement braces while the patches of others make it through?
Yeah, I'm neglecting the fact that we're not consistent as maintainers and I'm all for dropping it from
CODING_STYLE.
I'd rather expand the document. For example, I like the approach libvirt takes:
http://libvirt.org/git/?p=libvirt.git;a=blob_plain;f=HACKING;hb=HEAD
Not specifically to braces, but they describe types and memory allocation etc. which is FAQ stuff for us too.
Quoted 9 lines · Blue Swirl
Quoted 3 lines
Yeah, I'm neglecting the fact that we're not consistent as maintainers and I'm all for dropping it from
CODING_STYLE.I'd rather expand the document. For example, I like the approach libvirt takes:
http://libvirt.org/git/?p=libvirt.git;a=blob_plain;f=HACKING;hb=HEADNot specifically to braces, but they describe types and memory allocation etc. which is FAQ stuff for us too.
I agree 100%. There are a lot of idioms in QEMU that would be good to document for people learning the code base.
But I think that's orthogonal to the discussion of whether we want to keep the if rule and whether we want to enforce all of coding style at commit time.
Regards,
Anthony Liguori
Quoted 3 lines · Kevin Wolf
Am 02.08.2010 17:20, schrieb Anthony Liguori:
Quoted 2 lines · Aurelien Jarno
Quoted 1 line · Blue Swirl
[..snip..]
Quoted 11 lines
Quoted 8 lines
So really, I think the problem is that we're enforcing the words of
CODING_STYLEinstead of the intent. The intent ofCODING_STYLEis to improve the readability of the code. I think it requires a certain amount of taste to be applied.Rejecting a big patch because braces aren't used in single line if statements seems to be an unnecessary barrier to me.
Taking such patches anyway is basically what we're doing today, right? And what malc is complaining about.
Malc is mainly complaining about "Quod licet Jovi non licet bovi" situation.
Signature · 1 line
mailto:[email protected]
Quoted 9 lines · malc
Quoted 6 lines
Quoted 3 lines
Rejecting a big patch because braces aren't used in single line if statements seems to be an unnecessary barrier to me.
Taking such patches anyway is basically what we're doing today, right? And what malc is complaining about.
Malc is mainly complaining about "Quod licet Jovi non licet bovi" situation.
Very fair point.
Regards,
Anthony Liguori
Quoted 45 lines · Anthony Liguori
Quoted 24 lines · Aurelien Jarno
Quoted 12 lines · Blue Swirl
Quoted 8 lines · malc
History has shown that this particular rule is unenforcable.
Signed-off-by malc<[email protected]>---
CODING_STYLE | 11 ++++++-----1 files changed, 6 insertions(+), 5 deletions(-)Quoted 8 lines
Not again:
http://lists.nongnu.org/archive/html/qemu-devel/2009-12/msg00484.htmlThere are plenty of ways to make the rule enforceable, for example we could agree to start to revert commits which introduce new
CODING_STYLEviolations.Quoted 5 lines
It seems to be possible to add a pre-applypatch script to the git hook directory, that will verify the commit and reject it if it doesn't comply with the coding rules. Of course it's possible to commit a patch anyway by using --no-verify.
There are certain aspects of
CODING_STYLEthat I think are pretty important. For instance, space vs. tabs can really screw things up for people that have non-standard tabs. This is something that enforcing at patch submission time seems to be really important.Type naming seems important too because it's often not isolated. IOW, a poor choice in one file can end up polluting other files quickly that require interacting. The result is a mess of naming styles.
But something like braces around an if doesn't seem like it creates a big problem. Most C programmers are used to seeing braces in some statements and not other. Therefore, it's hard to argue that the code gets really unreadable if this isn't strictly enforced.
Quoted 4 lines
So really, I think the problem is that we're enforcing the words of
CODING_STYLEinstead of the intent. The intent ofCODING_STYLEis to improve the readability of the code. I think it requires a certain amount of taste to be applied.
The problem with that approach is that CODING_STYLE is not written like that at all. All four requirements equally state that they describe QEMU coding style. There is also no room left for
interpretation: "Every indented statement is braced; even if the block contains just one
statement."