[Nfd-dev] code-style "make incompleteness of split lines obvious" vs chained operations

Junxiao Shi shijunxiao at email.arizona.edu
Wed Mar 11 15:45:00 PDT 2015


Dear folks

Rule 1.12 says:

The incompleteness of split lines must be made obvious.

Split lines occurs when a statement exceed the 80 column limit given above.
It is difficult to give rigid rules for how lines should be split, but the
examples above should give a general hint.

In general:


   - Break after a comma.
      - Break after an operator.
      - Align the new line with the beginning of the expression on the
      previous line.



I'm curious how to format the following snippet: (for this example, let's
suppose it doesn't fit in the line width limit)

return QString("%1:%2:%3)
       .arg(localTime->tm_hour, 2, 10, '0')
       .arg(localTime->tm_min, 2, 10, '0')
       .arg(localTime->tm_sec, 2, 10, '0');

Technically ')' is an operator so I can break after it, but this doesn't
make the incompleteness obvious.


If I break after the dot operator, the snippet becomes:

return QString("%1:%2:%3).
         arg(localTime->tm_hour, 2, 10, '0').
         arg(localTime->tm_min, 2, 10, '0').
         arg(localTime->tm_sec, 2, 10, '0');

but the bare "arg" in the front doesn't look good.


If I break after the '(' operator, the snippet becomes:

return QString("%1:%2:%3).arg(
         localTime->tm_hour, 2, 10, '0').arg(
         localTime->tm_min, 2, 10, '0').arg(
         localTime->tm_sec, 2, 10, '0');

but this is also weird.


If I break after the comma, the snippet becomes:

return QString("%1:%2:%3).arg(localTime->tm_hour,
                              2, 10, '0').arg(localTime->tm_min,
                                              2, 10, '0')
.arg(localTime->tm_sec,
                                                              2, 10, '0');

which looks even worse.


Yours, Junxiao
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.lists.cs.ucla.edu/pipermail/nfd-dev/attachments/20150311/97718447/attachment.html>


More information about the Nfd-dev mailing list