[DTrace-devel] [PATCH v2] Refactoring for greater stylistic consistency
Eugene Loh
eugene.loh at oracle.com
Fri Jan 8 11:10:12 PST 2021
On 01/08/2021 06:26 AM, Kris Van Hees wrote:
> On Wed, Jan 06, 2021 at 03:30:40PM -0500,eugene.loh at oracle.com wrote:
>> diff --git a/CODING-STYLE b/CODING-STYLE
>> +Braces should typically be avoided on single-statement branches. E.g.,
>> + if (foo1) {
>> + bar1();
>> + bar2();
>> + } else
>> + bar3();
> Braces should be avoided on single-statement branches, unless one of the
> branches (other than the else-branch) contains multiple statements.
>
> GOOD:
> if (foo1) {
> bar1();
> } else if (foo2) {
> bar2();
> bar3();
> } else
> bar4();
It seems to me that the rule and the example conflict. Here, one of the
branches other than the else branch contains multiple statements.
Therefore, the "unless" condition is triggered. Therefore, the "avoid
braces" practice should not be used, not even on the "else bar4()"
branch. Complicated.
And, do "else" branches include "else if" branches?
The rule that I think is being illustrated seems hard to state and not
present in any style guide I managed to find. Do you mean:
When a simple-else branch has only a single, simple statement,
its braces should be omitted. Further, when the other branches
are all, each, single, simple statements, their braces should also
be omitted.
Or, how about employing a simpler rule, like the one in the Linux
kernel? That is, omit the "other than the else-branch" exception.
> BAD:
> if (foo1)
> bar1();
> else if (foo2) {
> bar2();
> bar3();
> } else
> bar4();
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://oss.oracle.com/pipermail/dtrace-devel/attachments/20210108/79e1e7d0/attachment.html
More information about the DTrace-devel
mailing list