[ovs-dev] [PATCH] coding-style: Explain when to break lines before or after binary operators.

Ben Pfaff blp at ovn.org
Fri Dec 1 19:23:27 UTC 2017


On Fri, Dec 01, 2017 at 07:01:12PM +0000, Tiago Lam wrote:
> Hi Ben,
> 
> A small in-line comment,
> 
> On 11/29/2017 12:37 AM, Ben Pfaff wrote:
> >+    if (!isdigit((unsigned char)s[0]) ||
> >+        !isdigit((unsigned char)s[1]) ||
> >+        !isdigit((unsigned char)s[2])) {
> >+        printf("string %s does not start with 3-digit code\n", s);
> >+    }
> >-    *idxp = ((l1_idx << PORT_ARRAY_L1_SHIFT)
> >-             | (l2_idx << PORT_ARRAY_L2_SHIFT)
> >-             | (l3_idx << PORT_ARRAY_L3_SHIFT));
> >+Do parenthesize a subexpression that must be split across more than one line,
> >+e.g.::
> >+
> >+    *idxp = ((l1_idx << PORT_ARRAY_L1_SHIFT) |
> >+             (l2_idx << PORT_ARRAY_L2_SHIFT) |
> >+             (l3_idx << PORT_ARRAY_L3_SHIFT));
> >+
> >+Breaking a long line before a binary operator gives its operands a more
> >+consistent look, since each operand has the same horizontal position.  This
> >+makes the end-of-line position a good choice when the operands naturally
> >+resemble each other, as in the previous two examples.  On the other hand,
> >+breaking after a binary operator better draws the eye to the operator, which
> >+can help clarify code by making it more obvious what's happening, such as in
> >+the following example::
> 
> It seems that this last sentence above and the example pointed to below is
> backwards. Should say, "On the other hand, breaking *before* a binary
> operator better draws the eye to the operator".

You're right.  Thank you.

I sent v2:
        https://patchwork.ozlabs.org/patch/843686/


More information about the dev mailing list