On Fri, Nov 11, 2016 at 4:50 AM, Junio C Hamano <gitster@xxxxxxxxx> wrote: > Karthik Nayak <karthik.188@xxxxxxxxx> 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 {}. I see, I mistook Jacob then. I was talking about if we need to use {} whenever there's only a single line of code but followed by a comment which extends the if/else if/.../else block. -- Regards, Karthik Nayak