Karthik Nayak <[email protected]> writes:
>> Minor nit. I'm not sure what standard we use here at Git, but
>> traditionally, I prefer to see { } blocks on all sections even if only
>> one of them needs it. (That is, only drop the braces when every
>> section is one line.) It also looks weird with a comment since it
>> appears as multiple lines to the reader. I think the braces improve
>> readability.
>>
>> I don't know whether that's Git's code base standard or not, however.
>> It's not really worth a re-roll unless something else would need to
>> change.
>>
> I believe this is the syntax followed in Git, xdiff/xmerge.c:173 and so on.
That is a bad example for two reasons, if you mean this part:
if ((size = file->recs[i]->size) &&
file->recs[i]->ptr[size - 1] == '\n')
/* Last line; ends in LF; Is it CR/LF? */
return size > 1 &&
file->recs[i]->ptr[size - 2] == '\r';
* if (!i)
/* The only line has no eol */
return -1;
/* Determine eol from second-to-last line */
What Jacob prefers is this:
---------------------------------------------
if (cond)
simple;
else if (cond)
simple;
else
simple;
---------------------------------------------
if (cond) {
simple;
} else if (cond) {
no;
longer;
simple;
} else {
simple;
}
---------------------------------------------
That is, as long as all arms of if/else if/.../else cascade is
simple, {} is used nowhere in the cascade, but once even one of them
requires {} then all others gain {}.