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

Davide Pesavento davide.pesavento at lip6.fr
Wed Mar 11 16:23:36 PDT 2015


On Thu, Mar 12, 2015 at 12:17 AM, Junxiao Shi
<shijunxiao at email.arizona.edu> wrote:
> Dear folks
>
> Thanks JeffT for pointing out this snippet.
> I have more questions about the alignment.
> (for the example, let's assume two .append() calls cannot fit on the same
> line)
>
>
> 1. Why not align '.append' of subsequent lines (rule 3.23), given the part
> before it ("certName") is short?
>
> certName.append(signingIdentity)
>         .append("KEY")
>         .append(keyName.getSubName(signingIdentity.size()))
>         .append("ID-CERT")
>         .appendVersion();
>
> I feel this looks better than indent subsequent lines with two spaces.
>

Agreed.

>
> 2. What if "certName" is a shorter identifier?
>
> (a)
>
> n.append(signingIdentity)
>   .append("KEY")
>   .append(keyName.getSubName(signingIdentity.size()))
>   .append("ID-CERT")
>   .appendVersion();
>
> (b)
>
> n.append(signingIdentity)
>  .append("KEY")
>  .append(keyName.getSubName(signingIdentity.size()))
>  .append("ID-CERT")
>  .appendVersion();
>
> I feel (b) looks better.
>

Just use a longer name for the identifier. 'n' isn't descriptive anyways.

> 3. Suppose there's a 'return' in the front, how should I align subsequent
> lines?
>
> (a)
>
> return certName.append(signingIdentity)
>   .append("KEY")
>   .append(keyName.getSubName(signingIdentity.size()))
>   .append("ID-CERT")
>   .appendVersion();
>
> (b)
>
> return certName.append(signingIdentity)
>        .append("KEY")
>        .append(keyName.getSubName(signingIdentity.size()))
>        .append("ID-CERT")
>        .appendVersion();
>
> (c)
>
> return certName.append(signingIdentity)
>          .append("KEY")
>          .append(keyName.getSubName(signingIdentity.size()))
>          .append("ID-CERT")
>          .appendVersion();
> (d)
>
> return certName.append(signingIdentity)
>                .append("KEY")
>                .append(keyName.getSubName(signingIdentity.size()))
>                .append("ID-CERT")
>                .appendVersion();
>
> I'd prefer (d).
> (a) and (c) also look nice, in case (d) would exceed column limit.
> (b) is worse than (a) and (c).
>

Obviously (d) is to be preferred, for consistency with example 1.

Best,
Davide



More information about the Nfd-dev mailing list