[Nfd-dev] code-style "make incompleteness of split lines obvious" vs chained operations
Thompson, Jeff
jefft0 at remap.UCLA.EDU
Wed Mar 11 16:06:08 PDT 2015
ndn-cxx already has plenty of code with the first option. This looks good to me. For example:
https://github.com/named-data/ndn-cxx/blob/34a37630a14c67309467074b448057dbf62cda65/src/security/key-chain.cpp#L338
certName.append(signingIdentity)
.append("KEY")
.append(keyName.getSubName(signingIdentity.size()))
.append("ID-CERT")
.appendVersion();
- Jeff T
From: Junxiao Shi <shijunxiao at email.arizona.edu<mailto:shijunxiao at email.arizona.edu>>
Date: Wednesday, March 11, 2015 at 15:45
To: nfd-dev <nfd-dev at lists.cs.ucla.edu<mailto:nfd-dev at lists.cs.ucla.edu>>
Subject: [Nfd-dev] code-style "make incompleteness of split lines obvious" vs chained operations
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/5f984415/attachment.html>
More information about the Nfd-dev
mailing list