[cfe-commits] r171039 - in /cfe/trunk: include/clang/Format/Format.h lib/Format/Format.cpp lib/Format/UnwrappedLineParser.cpp lib/Format/UnwrappedLineParser.h

Chandler Carruth chandlerc at google.com
Wed Dec 26 02:27:51 PST 2012


On Tue, Dec 25, 2012 at 2:31 AM, Sean Silva <silvas at purdue.edu> wrote:

> On Tue, Dec 25, 2012 at 3:10 AM, Daniel Jasper <djasper at google.com> wrote:
> > } else if (aaaaaaaa ==
> >            bbbbbbbb) ...
>
> My gut feeling is that most people would prefer this one.
>

Given this example, I agree. I think it gets more complicated though:

} else if (aaaaaaaa ==
           bbbbbbbb &&
           cccccccc ==
           dddddddd) {

So, here we have a bit of a conundrum. In an ideal world, what I would
really like is to see an indentation strategy which indicates operator
precedence easily to the reader. Now, I've never imagined actually doing
this because I'd just get it wrong and never update it. But with
clang-format, I think the more complex formatting might be something worth
considering.... But I've not yet come up with a good set of rules that
would format consistently and well while indicating precedence whenever
possible. Maybe Daniel has some strategies in mind? I've not thought much
about it. In this limited case, I would personally find the following ever
so slightly easier to read:

} else if (aaaaaaaa ==
               bbbbbbbb &&
           cccccccc ==
               dddddddd) {

Mostly this is because I subscribe to the 'black indent of 2 spaces, line
continuation of 4 spaces' school of formatting, and I'm just using
indentation is a blunt instrument to indicate grouping. If extra
parentheses weren't used to silence valuable warnings, my preference would
be:

} else if ((aaaaaaaa ==
            bbbbbbbb) &&
           (cccccccc ==
            dddddddd)) {
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20121226/4c4f43c3/attachment.html>


More information about the cfe-commits mailing list