Changeset View
Standalone View
share/man/man9/style.9
Show First 20 Lines • Show All 497 Lines • ▼ Show 20 Lines | default: | ||||
usage(); | usage(); | ||||
} | } | ||||
argc -= optind; | argc -= optind; | ||||
argv += optind; | argv += optind; | ||||
.Ed | .Ed | ||||
.Pp | .Pp | ||||
Space after keywords | Space after keywords | ||||
.Pq Ic if , while , for , return , switch . | .Pq Ic if , while , for , return , switch . | ||||
No braces | No braces | ||||
wblock: "Either braces" can be misunderstood ("Either { or (", for example).
Since everyone else has… | |||||
Not Done Inline ActionsThis is better, but still too wordy. I don't like it any better than what we have now. imp: This is better, but still too wordy. I don't like it any better than what we have now. | |||||
.Ql ( \&{ | .Ql ( \&{ | ||||
and | and | ||||
.Ql \&} ) | .Ql \&} ) | ||||
are | are generally | ||||
used for control statements with zero or only a single statement unless that | used for control statements with zero or only a single statement unless that | ||||
statement is more than a single line in which case they are permitted. | statement is more than a single line in which case they are permitted. | ||||
New code, however, can choose to always use braces for single statements. | |||||
gnnUnsubmitted Done Inline ActionsStrike this prevarication and leave the "generally" on line 510. gnn: Strike this prevarication and leave the "generally" on line 510. | |||||
allanjudeUnsubmitted Done Inline ActionsThe use of braces { and } for control statements with zero or only a single statement is optional. In all other cases, the braces are required. allanjude: The use of braces { and } for control statements with zero or only a single statement is… | |||||
Done Inline ActionsThat's different than what I'm saying. You must do it for the whole file. not pick and choose willy nilly. There wasn't support for relaxing it that much. imp: That's different than what I'm saying. You must do it for the whole file. not pick and choose… | |||||
Done Inline ActionsThe use of braces allanjude: The use of braces
.Ql ( \&{
and
.Ql \&} )
for control statements containing only a line is… | |||||
Not Done Inline ActionsI would move "allowed" earlier ("two styles of braces ({ }) are allowed for single line statements"). Otherwise, looks okay. wblock: I would move "allowed" earlier ("two styles of braces ({ }) are allowed for single line… | |||||
Not Done Inline ActionsI do think it reads better to move "are allowed" sooner in the sentence. gad: I do think it reads better to move "are allowed" sooner in the sentence. | |||||
Forever loops are done with | Forever loops are done with | ||||
.Ic for Ns 's , | .Ic for Ns 's , | ||||
Done Inline Actions"...are not...with only...unless...is more...are always..." is like one too many half-twist backflips for my mind. How about something like: Within a file, braces are either consistantly used for every control statement, or they are consistantly used only for control statements with multiple lines. ian: "...are not...with only...unless...is more...are always..." is like one too many half-twist… | |||||
Done Inline ActionsI like this wording. jonathan: I like this wording. | |||||
Done Inline ActionsAgree with @ian emaste: Agree with @ian | |||||
Done Inline Actionsjonathan: Sorry, by "this wording", I meant "@ian's wording". As in, "I also agree with @ian". :) | |||||
Done Inline ActionsBut Ian's wording changes the meaning of what we have there now. While it is simpler, it is less clear as a result. imp: But Ian's wording changes the meaning of what we have there now. While it is simpler, it is… | |||||
Not Done Inline ActionsIn what way does it change the meaning? Either you consistantly always use braces, or you consistantly only use them to enclose multiple lines (leaving single lines braceless). ian: In what way does it change the meaning? Either you consistantly always use braces, or you… | |||||
Done Inline Actionsyou left off the 'except for clarity' or 'when things span multiple lines' or some variation. That bit is important. imp: you left off the 'except for clarity' or 'when things span multiple lines' or some variation. | |||||
Done Inline ActionsI just think removal of the requirement to NOT have them is enough. The wording here seems clunky. julian: I just think removal of the requirement to NOT have them is enough. The wording here seems… | |||||
Done Inline ActionsI don't like having to use them consistently in the same file, for a point brought up by julian. In nested conditionals, as in if, else-if, else-if, it may be aesthetically pleasing to see the braces all match, but yet not have to have braces for simple single statement conditions elsewhere in the file. deischen: I don't like having to use them consistently in the same file, for a point brought up by julian. | |||||
Done Inline ActionsRe all the noise: "Should" not "Must". We strongly encourage style within a file to be consistent elsewhere, and this just reinforces it. You should do this, but if there's a good reason not to do it, then "should" covers that. imp: Re all the noise: "Should" not "Must". We strongly encourage style within a file to be… | |||||
Not Done Inline ActionsI'm in favor of any update which relaxes the rules on this, as I do think there are times when it's better to have braces around single-line statements. I'd like to see the rules relaxed a bit more to say that in the case of this braces-rule, usage should be consistent with a subroutine, instead of the entire source file. I do prefer file-wide consistency for most rules. But in thinking over code that I've written, there are some subroutines where it helps me to have the extra braces when I'm working on that routine. (The braces help when I'm constantly adding/removing statements for debugging purposes). And yes, the main reason I'm saying this is just to make sure I understand how to comment on changes in Phabricator. gad: I'm in favor of any update which relaxes the rules on this, as I do think there are times when… | |||||
not | not | ||||
.Ic while Ns 's . | .Ic while Ns 's . | ||||
.Bd -literal | .Bd -literal | ||||
for (p = buf; *p != '\e0'; ++p) | for (p = buf; *p != '\e0'; ++p) | ||||
; /* nothing */ | ; /* nothing */ | ||||
for (;;) | for (;;) | ||||
stmt; | stmt; | ||||
for (;;) { | for (;;) { | ||||
Show All 37 Lines | |||||
followed by spaces | followed by spaces | ||||
to form the indentation. | to form the indentation. | ||||
Do not use more spaces than a tab will produce | Do not use more spaces than a tab will produce | ||||
and do not use spaces in front of tabs. | and do not use spaces in front of tabs. | ||||
.Pp | .Pp | ||||
Closing and opening braces go on the same line as the | Closing and opening braces go on the same line as the | ||||
.Ic else . | .Ic else . | ||||
Braces that are not necessary may be left out. | Braces that are not necessary may be left out. | ||||
Braces that are not necessary may also be left in for new | |||||
code that uses this rule consistently. | |||||
.Bd -literal | .Bd -literal | ||||
gnnUnsubmitted Done Inline ActionsThe decision to use braces that are not strictly necessary is left to the developer but whichever choice is made it must be applied consistently to the entire file. gnn: The decision to use braces that are not strictly necessary is left to the developer but… | |||||
rodrigcUnsubmitted Done Inline ActionsI agree with @gnn rodrigc: I agree with @gnn | |||||
Done Inline ActionsI prefer @gnn's wording, it is less contradictory. allanjude: I prefer @gnn's wording, it is less contradictory. | |||||
Done Inline Actionsgnn's wording is still too verbose, but it was a comment against a much earlier draft. imp: gnn's wording is still too verbose, but it was a comment against a much earlier draft. | |||||
Done Inline ActionsAlso, it turns out that the changes in this part of the file aren't needed at all, so I reverted back to the original. imp: Also, it turns out that the changes in this part of the file aren't needed at all, so I… | |||||
if (test) | if (test) | ||||
stmt; | stmt; | ||||
else if (bar) { | else if (bar) { | ||||
stmt; | stmt; | ||||
stmt; | stmt; | ||||
} else | } else | ||||
stmt; | stmt; | ||||
.Ed | .Ed | ||||
▲ Show 20 Lines • Show All 280 Lines • Show Last 20 Lines |
"Either braces" can be misunderstood ("Either { or (", for example).
Since everyone else has had a shot at this, here is mine:
The choice of enclosing control statements in braces
.Pq Ql \&{ and Ql \&}
when they contain zero or one statements is left up to the author.
However, the chosen style must be used consistently throughout the entire file.
(Markup on the Pq line probably needs work. I'm also not keen on the redundant statement, but can blame it on sleep deprivation.)