Update the CodingGuidelines
cover Update the CodingGuidelines
After seeing a large torrent of patches from Elia, I was re-reading the CodingGuidelines to see if our preference of $( ... ) over ... was properly described, and then I spotted a typo and also lack of examples on a few points that I recall pointing out during recent reviews, which grew to this series.
Junio C Hamano (8):
CodingGuidelines: typofix
CodingGuidelines: give an example for case/esac statement
CodingGuidelines: give an example for redirection
CodingGuidelines: give an example for control statements
CodingGuidelines: give an example for shell function preamble
CodingGuidelines: call the conditional statement "if ()", not "if()"
CodingGuidelines: on comparison
CodingGuidelines: once it is in, it is not worth the code churn
Documentation/CodingGuidelines | 81 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 75 insertions(+), 6 deletions(-)
Signature · 1 line
2.0.0-rc1-355-gd6d6511
PATCH 1/8 CodingGuidelines: typofix
The sentence lacked the necessary verb.
--- Documentation/CodingGuidelines | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Documentation/CodingGuidelines +1 -1
@@ -15,7 +15,7 @@ code. For Git in general, three rough rules are: let's use it". Again, we live in the real world, and it is sometimes a - judgement call, the decision based more on real world + judgement call, the decision is based more on real world constraints people face than what the paper standard says. Make your code readable and sensible, and don't try to be clever.
Signature · 1 line
2.0.0-rc1-355-gd6d6511
Re: [PATCH 1/8] CodingGuidelines: typofix
Quoted 1 line · Junio C Hamano
The sentence lacked the necessary verb.
No, it didn't.
Documentation/CodingGuidelines code. For Git in general, three rough rules are: · line 17
Quoted 13 lines
Signed-off-by Junio C Hamano <[email protected]>--- Documentation/CodingGuidelines | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)Documentation/CodingGuidelines +0
-0@@ -15,7 +15,7 @@ code. For Git in general, three rough rules are: let's use it". Again, we live in the real world, and it is sometimes a
^^
Documentation/CodingGuidelines code. For Git in general, three rough rules are: · line 19
Quoted 3 lines
Documentation/CodingGuidelines +1
-1- judgement call, the decision based more on real world + judgement call, the decision is based more on real world constraints people face than what the paper standard says.
There is one common "is" for original statement and paraphrase. Adding another one turns this into two sentences which cannot sensibly be connected with a comma.
If you want to fix something here, do s/judgement/judgment/ instead.
Signature · 1 line
David Kastrup
Re: [PATCH 1/8] CodingGuidelines: typofix
Quoted 20 lines · David Kastrup
Quoted 1 line · Junio C Hamano
The sentence lacked the necessary verb.
No, it didn't.
Documentation/CodingGuidelines code. For Git in general, three rough rules are: · line 17
Quoted 13 lines
Signed-off-by Junio C Hamano <[email protected]>--- Documentation/CodingGuidelines | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)Documentation/CodingGuidelines +0
-0@@ -15,7 +15,7 @@ code. For Git in general, three rough rules are: let's use it". Again, we live in the real world, and it is sometimes a^^
Quoted 7 lines
Documentation/CodingGuidelines code. For Git in general, three rough rules are: · line 19
Quoted 3 lines
Documentation/CodingGuidelines +1
-1- judgement call, the decision based more on real world + judgement call, the decision is based more on real world constraints people face than what the paper standard says.There is one common "is" for original statement and paraphrase. Adding another one turns this into two sentences which cannot sensibly be connected with a comma.
Thanks for spotting.
I thought (but I see I didn't by mistake) that I split them into two sentences, replacing the comma with a semicolon.
Quoted 1 line
If you want to fix something here, do s/judgement/judgment/ instead.
That too.
PATCH 2/8 CodingGuidelines: give an example for case/esac statement
In reply to Junio C Hamano--- Documentation/CodingGuidelines | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)
Documentation/CodingGuidelines +11 -1
@@ -34,7 +34,17 @@ For shell scripts specifically (not exhaustive): - We use tabs for indentation. - - Case arms are indented at the same depth as case and esac lines. + - Case arms are indented at the same depth as case and esac lines, + like this: + + case "$variable" in + pattern1) + do this + ;; + pattern2) + do that + ;; + esac - Redirection operators should be written with space before, but no space after them. In other words, write 'echo test >"$file"'
Signature · 1 line
2.0.0-rc1-355-gd6d6511
PATCH 3/8 CodingGuidelines: give an example for redirection
In reply to Junio C Hamano--- Documentation/CodingGuidelines | 6 ++++++ 1 file changed, 6 insertions(+)
Documentation/CodingGuidelines +6 -0
@@ -53,6 +53,12 @@ For shell scripts specifically (not exhaustive): redirection target in a variable (as shown above), our code does so because some versions of bash issue a warning without the quotes. + cat hello > world < universe # incorrect + cat hello >world <universe # correct + + echo hello >$world # incorrect + echo hello >"$world" # correct + - We prefer $( ... ) for command substitution; unlike ``, it properly nests. It should have been the way Bourne spelled it from day one, but unfortunately isn't.
Signature · 1 line
2.0.0-rc1-355-gd6d6511
PATCH v2 3/8 CodingGuidelines: give an example for redirection
---
* Instead of using trailing "# correct" comment on each of the one-liners, group the good ones and the bad ones into two groups and give (incorrect)/(correct) header like the other patches as suggested. How does this look?
The only reason I originally did these differently is because these are two independent examples, and I thought it would make the difference stand out better to the readers if we showed good/bad pairs of "cat" and "echo" that way. But as long as we are not going to add more examples here, I think the result is not too bad.
Documentation/CodingGuidelines | 8 ++++++++ 1 file changed, 8 insertions(+)
Documentation/CodingGuidelines +8 -0
@@ -61,6 +61,14 @@ For shell scripts specifically (not exhaustive): redirection target in a variable (as shown above), our code does so because some versions of bash issue a warning without the quotes. + (incorrect) + cat hello > world < universe + echo hello >$world + + (correct) + cat hello >world <universe + echo hello >"$world" + - We prefer $( ... ) for command substitution; unlike ``, it properly nests. It should have been the way Bourne spelled it from day one, but unfortunately isn't.
Signature · 1 line
2.0.0-rc1-355-gd6d6511
PATCH 4/8 CodingGuidelines: give an example for control statements
In reply to Junio C Hamano--- Documentation/CodingGuidelines | 11 +++++++++++ 1 file changed, 11 insertions(+)
Documentation/CodingGuidelines +11 -0
@@ -97,6 +97,17 @@ For shell scripts specifically (not exhaustive): "then" should be on the next line for if statements, and "do" should be on the next line for "while" and "for". + (incorrect) + if test -f hello; then + do this + fi + + (correct) + if test -f hello + then + do this + fi + - We prefer "test" over "[ ... ]". - We do not write the noiseword "function" in front of shell
Signature · 1 line
2.0.0-rc1-355-gd6d6511
Re: [PATCH 4/8] CodingGuidelines: give an example for control statements
Quoted 10 lines · Junio C Hamano
Signed-off-by Junio C Hamano <[email protected]>--- Documentation/CodingGuidelines | 11 +++++++++++ 1 file changed, 11 insertions(+)Documentation/CodingGuidelines +0
-0
Documentation/CodingGuidelines For shell scripts specifically (not exhaustive): · line 100
Quoted 4 lines
Documentation/CodingGuidelines +1
-0@@ -97,6 +97,17 @@ For shell scripts specifically (not exhaustive): "then" should be on the next line for if statements, and "do" should be on the next line for "while" and "for". + (incorrect)
At the other patches you used #comments behind oneliners,
not sure if that's also suitable here for consistency of the documentation.
Quoted 14 lines
Documentation/CodingGuidelines +10
-0+ if test -f hello; then + do this + fi + + (correct) + if test -f hello + then + do this + fi + - We prefer "test" over "[ ... ]". - We do not write the noiseword "function" in front of shell
Re: [PATCH 4/8] CodingGuidelines: give an example for control statements
Quoted 14 lines · Stefan Beller
Quoted 13 lines · Junio C Hamano
Signed-off-by Junio C Hamano <[email protected]>--- Documentation/CodingGuidelines | 11 +++++++++++ 1 file changed, 11 insertions(+)Documentation/CodingGuidelines +0
-0@@ -97,6 +97,17 @@ For shell scripts specifically (not exhaustive): "then" should be on the next line for if statements, and "do" should be on the next line for "while" and "for".
Quoted 4 lines
Documentation/CodingGuidelines For shell scripts specifically (not exhaustive): · line 100
Quoted 1 line
Documentation/CodingGuidelines +1
-0+ (incorrect)At the other patches you used #comments behind oneliners,
not sure if that's also suitable here for consistency of the documentation.
I think you meant this one (are there others?):
+ cat hello > world < universe # incorrect
+ cat hello >world <universe # correct
+
+ echo hello >$world # incorrect
+ echo hello >"$world" # correct
+
I can certainly go with this instead over there:
(incorrect)
cat hello > world < universe
echo hello >$world
(correct)
cat hello >world <universe
echo hello >"$world"
I do not think it is wise to use the trailing comment style on all the incorrect/correct lines for these examples.
Quoted 14 lines
Quoted 14 lines
Documentation/CodingGuidelines +10
-0+ if test -f hello; then + do this + fi + + (correct) + if test -f hello + then + do this + fi + - We prefer "test" over "[ ... ]". - We do not write the noiseword "function" in front of shell
Re: [PATCH 4/8] CodingGuidelines: give an example for control statements
In reply to Junio C HamanoQuoted 17 lines · Junio C Hamano
Signed-off-by Junio C Hamano <[email protected]>--- Documentation/CodingGuidelines | 11 +++++++++++ 1 file changed, 11 insertions(+)Documentation/CodingGuidelines +4
-0@@ -97,6 +97,17 @@ For shell scripts specifically (not exhaustive): "then" should be on the next line for if statements, and "do" should be on the next line for "while" and "for". + (incorrect) + if test -f hello; then + do this + fi
Documentation/CodingGuidelines For shell scripts specifically (not exhaustive): · line 113
Quoted 10 lines
Documentation/CodingGuidelines +7
-0+ + (correct) + if test -f hello + then + do this + fi + - We prefer "test" over "[ ... ]". - We do not write the noiseword "function" in front of shell
s/noiseword/bashism/
Signature · 1 line
David Kastrup
Re: [PATCH 4/8] CodingGuidelines: give an example for control statements
Quoted 3 lines · David Kastrup
Quoted 1 line
- We do not write the noiseword "function" in front of shell
s/noiseword/bashism/
That is outside the scope of this patch, but since you brought it up...
I did consider between noiseword and bashism when I wrote this part, and decided against "bashism". XCU 2.4 "Reserved Words" lists it (among others) and says
... may be recognized as reserved words on some implementations ... causing unspecified results
Even if "bash" were not the only shell that uses "function" keyword to introduce a shell function definition, we wouldn't use it. As we say in the introductory part, we may say "It is not in POSIX, but it is supported so widely and using it give us so great a benefit, so we do use it" for some things, but "function" is not one of them.
The reason is because it is a noiseword and its use is not necessary in order to define a shell function.
PATCH 5/8 CodingGuidelines: give an example for shell function preamble
In reply to Junio C Hamano--- Documentation/CodingGuidelines | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-)
Documentation/CodingGuidelines +11 -3
@@ -113,9 +113,17 @@ For shell scripts specifically (not exhaustive): - We do not write the noiseword "function" in front of shell functions. - - We prefer a space between the function name and the parentheses. The - opening "{" should also be on the same line. - E.g.: my_function () { + - We prefer a space between the function name and the parentheses, + and no space inside the parentheses. The opening "{" should also + be on the same line. + + (incorrect) + my_function(){ + ... + + (correct) + my_function () { + ... - As to use of grep, stick to a subset of BRE (namely, no \{m,n\}, [::], [==], or [..]) for portability.
Signature · 1 line
2.0.0-rc1-355-gd6d6511
PATCH 6/8 CodingGuidelines: call the conditional statement "if ()", not "if()"
In reply to Junio C HamanoThe point immediately before it is about having SP after the control keyword. Follow it.
--- Documentation/CodingGuidelines | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Documentation/CodingGuidelines +1 -1
@@ -184,7 +184,7 @@ For C programs: of "else if" statements, it can make sense to add braces to single line blocks. - - We try to avoid assignments inside if(). + - We try to avoid assignments inside "if ()" condition. - Try to make your code understandable. You may put comments in, but comments invariably tend to stale out when the code
Signature · 1 line
2.0.0-rc1-355-gd6d6511
Re: [PATCH 6/8] CodingGuidelines: call the conditional statement "if ()", not "if()"
Quoted 13 lines · Junio C Hamano
The point immediately before it is about having SP after the control keyword. Follow it.
Signed-off-by Junio C Hamano <[email protected]>--- Documentation/CodingGuidelines | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)Documentation/CodingGuidelines +0
-0
Documentation/CodingGuidelines For C programs: · line 187
Quoted 5 lines
Documentation/CodingGuidelines +1
-1@@ -184,7 +184,7 @@ For C programs: of "else if" statements, it can make sense to add braces to single line blocks. - - We try to avoid assignments inside if(). + - We try to avoid assignments inside "if ()" condition.
That's not grammatical.
Signature · 1 line
David Kastrup
Re: [PATCH 6/8] CodingGuidelines: call the conditional statement "if ()", not "if()"
Quoted 4 lines · David Kastrup
Quoted 2 lines
- - We try to avoid assignments inside
if().
+ - We try to avoid assignments inside "if ()" condition.That's not grammatical.
OK,
... inside the condition part of an "if ()" statement.
then?
Re: [PATCH 6/8] CodingGuidelines: call the conditional statement "if ()", not "if()"
Quoted 5 lines · Junio C Hamano
Quoted 3 lines · David Kastrup
Quoted 2 lines
- - We try to avoid assignments inside
if().
+ - We try to avoid assignments inside "if ()" condition.
Quoted 7 lines
Quoted 1 line
That's not grammatical.
OK,
... inside the condition part of an "if ()" statement.
then?
... in the condition of an "if" statement
is what I would write. "if ()" statement is mixing name and shorthand for the statement.
Signature · 1 line
David Kastrup
PATCH 7/8 CodingGuidelines: on comparison
In reply to Junio C HamanoSee http://thread.gmane.org/gmane.comp.version-control.git/3903/focus=4126
--- Documentation/CodingGuidelines | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+)
Documentation/CodingGuidelines +26 -0
@@ -212,6 +212,32 @@ For C programs: - Double negation is often harder to understand than no negation at all. + - There are two schools of thought when it comes to comparison, + especially inside a loop. Some people prefer to have less stable + value on the left hand side and more stable value on the right hand + side, e.g. if you have a loop that counts variable i down to the + lower bound, + + while (i > lower_bound) { + do something; + i--; + } + + Other people prefer to have the textual order of values match the + actual order of values in their comparison, so that they can + mentally draw a number line from left to right and place these + values in order, i.e. + + while (lower_bound < i) { + do something; + i--; + } + + Both are valid, and we use both, even though we tend to see the + former the more preferable, the more "stable" the more stable side + becomes (comparison with a constant, "i > 0", is an extreme + example). Just do not mix styles in the same part of the code. + - Some clever tricks, like using the !! operator with arithmetic constructs, can be extremely confusing to others. Avoid them, unless there is a compelling reason to use them.
Signature · 1 line
2.0.0-rc1-355-gd6d6511
PATCH 8/8 CodingGuidelines: once it is in, it is not worth the code churn
In reply to Junio C Hamano--- Documentation/CodingGuidelines | 8 ++++++++ 1 file changed, 8 insertions(+)
Documentation/CodingGuidelines +8 -0
@@ -18,6 +18,14 @@ code. For Git in general, three rough rules are: judgement call, the decision is based more on real world constraints people face than what the paper standard says. + - Fixing style violations while working on a real change as a + preparatory clean-up step is good, but otherwise avoid useless code + churn for the sake of conforming to the style. + + "Once it _is_ in the tree, it's not really worth the patch noise to + go and fix it up." + Cf. http://article.gmane.org/gmane.linux.kernel/943020 + Make your code readable and sensible, and don't try to be clever. As for more concrete guidelines, just imitate the existing code
Signature · 1 line
2.0.0-rc1-355-gd6d6511
Re: [PATCH 1/8] CodingGuidelines: typofix
In reply to Junio C HamanoQuoted 3 lines · Junio C Hamano
Quoted 1 line
If you want to fix something here, do s/judgement/judgment/ instead.
That too.
FWIW, neither is outright wrong; it is an America/British variation, and apparently dictionaries disagree on which is preferred.
-Peff
Re: [PATCH 1/8] CodingGuidelines: typofix
Quoted 8 lines · Jeff King
Quoted 3 lines · Junio C Hamano
Quoted 1 line
If you want to fix something here, do s/judgement/judgment/ instead.
That too.
FWIW, neither is outright wrong; it is an America/British variation, and apparently dictionaries disagree on which is preferred.
My reading of various "grammar" sites was that even though variation exists[*1*], the form without 'e' is the traditionally preferred form, and that is why I said "That too".
But let's follow this one:
http://www.google.com/trends/explore#q=judgement%20call%2C%20judgment%20call&cmpt=q
which seems to say that with 'e' is more common.
[Footnote]
*1* To Americans, the form with 'e' is abomination. Wikipedia claims that (1) without 'e' is in legal and (2) with 'e' in other contexts in British (this particular one is a non-legal use), and
(3) both are equally acceptable in non-legal contexts in Austraria and Canada.
Re: [PATCH 7/8] CodingGuidelines: on comparison
In reply to Junio C HamanoQuoted 3 lines · Junio C Hamano
See http://thread.gmane.org/gmane.comp.version-control.git/3903/focus=4126
Signed-off-by Junio C Hamano <[email protected]>
Don't you often complain about submitters referencing a discussion in a commit message without providing some context or summary?
Documentation/CodingGuidelines For C programs: · line 219
Quoted 5 lines
+ - There are two schools of thought when it comes to comparison,
Documentation/CodingGuidelines +4
-0+ especially inside a loop. Some people prefer to have less stable + value on the left hand side and more stable value on the right hand + side, e.g. if you have a loop that counts variable i down to the + lower bound,
Grammar: /(less|more) stable/the &/
Documentation/CodingGuidelines For C programs: · line 240
Quoted 5 lines
Documentation/CodingGuidelines +5
-0+ Both are valid, and we use both, even though we tend to see the + former the more preferable, the more "stable" the more stable side + becomes (comparison with a constant, "i > 0", is an extreme + example). Just do not mix styles in the same part of the code. +
I had trouble parsing the first sentence. Maybe:
Both are valid, and we use both. However, the more "stable" the stable side becomes, the more we tend to prefer the former (comparison with a constant[...]
-Peff
Re: [PATCH 7/8] CodingGuidelines: on comparison
Quoted 8 lines · Jeff King
Quoted 3 lines · Junio C Hamano
See http://thread.gmane.org/gmane.comp.version-control.git/3903/focus=4126
Signed-off-by Junio C Hamano <[email protected]>Don't you often complain about submitters referencing a discussion in a commit message without providing some context or summary?
Yes, but the summary of the discussion would be identical to the new text added by the patch to the documentation tree in this case, so I didn't find a good introductory text before "See $URL". Perhaps
This comes up from time to time. See $URL for the original discussion.
but I do not know if that is much better.
Quoted 14 lines
Documentation/CodingGuidelines For C programs: · line 219
Quoted 5 lines
+ - There are two schools of thought when it comes to comparison,
Documentation/CodingGuidelines +4
-0+ especially inside a loop. Some people prefer to have less stable + value on the left hand side and more stable value on the right hand + side, e.g. if you have a loop that counts variable i down to the + lower bound,Grammar: /(less|more) stable/the &/
Documentation/CodingGuidelines For C programs: · line 240
Quoted 5 lines
Documentation/CodingGuidelines +5
-0+ Both are valid, and we use both, even though we tend to see the + former the more preferable, the more "stable" the more stable side + becomes (comparison with a constant, "i > 0", is an extreme + example). Just do not mix styles in the same part of the code. +
Quoted 5 lines
I had trouble parsing the first sentence. Maybe:
Both are valid, and we use both. However, the more "stable" the stable side becomes, the more we tend to prefer the former (comparison with a constant[...]
Thanks. That is much better.
Re: [PATCH 1/8] CodingGuidelines: typofix
In reply to Junio C HamanoQuoted 5 lines · Junio C Hamano
But let's follow this one:
http://www.google.com/trends/explore#q=judgement%20call%2C%20judgment%20call&cmpt=q
which seems to say that with 'e' is more common.
Grammar by democracy. ;)
Quoted 5 lines
*1* To Americans, the form with 'e' is abomination. Wikipedia claims that (1) without 'e' is in legal and (2) with 'e' in other contexts in British (this particular one is a non-legal use), and
(3) both are equally acceptable in non-legal contexts in Austraria and Canada.
That is what I found most interesting about the discussion. The reason I bothered to look it up and say something is that as an American, I would without a doubt spell it with the "e", contradicting what I found online. Oh well.
-Peff
Re: [PATCH 1/8] CodingGuidelines: typofix
Quoted 9 lines · Jeff King
Quoted 5 lines · Junio C Hamano
But let's follow this one:
http://www.google.com/trends/explore#q=judgement%20call%2C%20judgment%20call&cmpt=q
which seems to say that with 'e' is more common.
Grammar by democracy. ;)
Languages are a democracy. There's no authority that decides if "unibrow" should become part of the English language. We all do.
Signature · 1 line
Felipe Contreras
Re: [PATCH 1/8] CodingGuidelines: typofix
Quoted 5 lines · Felipe Contreras
Quoted 4 lines · Jeff King
Quoted 2 lines · Junio C Hamano
But let's follow this one:
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
http://www.google.com/trends/explore#q=judgement%20call%2C%20judgment%20call&cmpt=q
which seems to say that with 'e' is more common.
Grammar by democracy. ;)
Languages are a democracy. There's no authority that decides if "unibrow" should become part of the English language. We all do.
Well, and the U.S. justice system rather supports the hyphenation judge- mental.
Signature · 1 line
David Kastrup
Re: [PATCH 7/8] CodingGuidelines: on comparison
In reply to Junio C HamanoQuoted 11 lines · Junio C Hamano
Quoted 8 lines · Jeff King
Quoted 3 lines · Junio C Hamano
See http://thread.gmane.org/gmane.comp.version-control.git/3903/focus=4126
Signed-off-by Junio C Hamano <[email protected]>Don't you often complain about submitters referencing a discussion in a commit message without providing some context or summary?
Quoted 8 lines
Yes, but the summary of the discussion would be identical to the new text added by the patch to the documentation tree in this case, so I didn't find a good introductory text before "See $URL". Perhaps
This comes up from time to time. See $URL for the original discussion.
but I do not know if that is much better.
I meant something even less in-depth. Your message says only "on comparison", and I did not even know what "this" in your sentence above would mean until I followed the link.
There are arguments for writing a conditional as "a < b" rather than "b > a", or vice versa. Let's give guidance on which we prefer.
Not a big deal, but I think it is easy when you have just written the patch to forget that a reviewer or a reader of "git log" six months have no has no context at all.
-Peff
Re: [PATCH 7/8] CodingGuidelines: on comparison
Quoted 10 lines · Jeff King
I meant something even less in-depth. Your message says only "on comparison", and I did not even know what "this" in your sentence above would mean until I followed the link.
There are arguments for writing a conditional as "a < b" rather than "b > a", or vice versa. Let's give guidance on which we prefer.
Not a big deal, but I think it is easy when you have just written the patch to forget that a reviewer or a reader of "git log" six months have no has no context at all.
Thanks; I'll steal that one.
[PATCH 9/8] CodingGuidelines: on splitting a long line
In reply to Junio C Hamano--- Documentation/CodingGuidelines | 55 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+)
Documentation/CodingGuidelines +55 -0
@@ -249,6 +249,61 @@ For C programs: Just do not mix styles in the same part of the code and mimic existing styles in the neighbourhood. + - There are two schools of thought when it comes to splitting a long + logical line into multiple lines. Some people push the second and + subsequent lines far enough to the right with tabs and align them: + + if (the_beginning_of_a_very_long_expression_that_has_to || + span_more_than_a_single_line_of || + the_source_text) { + ... + + while other people prefer to align the second and the subsequent + lines with the column immediately inside the opening parenthesis, + with tabs and spaces, following our "tabstop is always a multiple + of 8" convention: + + if (the_beginning_of_a_very_long_expression_that_has_to || + span_more_than_a_single_line_of || + the_source_text) { + ... + + Both are valid, and we use both. Again, just do not mix styles in + the same part of the code and mimic existing styles in the + neighbourhood. + + - When splitting a long logical line, some people change line before + a binary operator, so that the result looks like a parse tree when + you turn your head 90-degrees counterclockwise: + + if (the_beginning_of_a_very_long_expression_that_has_to + || span_more_than_a_single_line_of_the_source_text) { + + while other people prefer to leave the operator at the end of the + line: + + if (the_beginning_of_a_very_long_expression_that_has_to || + span_more_than_a_single_line_of_the_source_text) { + + Both are valid, but we tend to use the latter more, unless the + expression gets fairly complex, in which case the former tends to + be easier to read. Again, just do not mix styles in the same part + of the code and mimic existing styles in the neighbourhood. + + - When splitting a long logical line, with everything else being + equal, it is preferrable to split after the operator at higher + level in the parse tree. That is, this is more preferrable: + + if (a_very_long_variable * that_is_used_in + + a_very_long_expression) { + ... + + than + + if (a_very_long_variable * + that_is_used_in + a_very_long_expression) { + ... + - Some clever tricks, like using the !! operator with arithmetic constructs, can be extremely confusing to others. Avoid them, unless there is a compelling reason to use them.
Signature · 1 line
2.0.0-rc1-355-gd6d6511
Re: [PATCH 9/8] CodingGuidelines: on splitting a long line
Quoted 2 lines · Junio C Hamano
+ - When splitting a long logical line, with everything else being
+ equal, it is preferrable to split after the operator at higher
dict.org says that it should be "preferable", not "preferrable".
Signature · 3 lines
brian m. carlson / brian with sandals: Houston, Texas, US +1 832 623 2791 | http://www.crustytoothpaste.net/~bmc | My opinion only OpenPGP: RSA v4 4096b: 88AC E9B2 9196 305B A994 7552 F1BA 225C 0223 B187