[cfe-dev] ClangFormat Additional Options Proposal

Daniel Jasper djasper at google.com
Wed Apr 30 01:49:50 PDT 2014


On Tue, Apr 29, 2014 at 6:14 PM, Haroogan <Haroogan at gmail.com> wrote:

> Hello Daniel,
>
> Thank you for answering. OK, I might add it myself as time permits,
> although
> I assumed that it would be quite simple to add for those who directly work
> on ClangFormat given the framework that is behind.
>
> Breaking after "::" is esoecially useful with class method definitions.
> Don't have to go far to search for example, just look into Clang or LLVM
> code base. A name of class could well be 40 characters long. If a method
> name is around 20 characters, then you just have 20 characters left for
> parentheses and parameters (assuming you've already wrapped return type
> according to 1st proposed option). Of course you can wrap parameters, but
> the point is that when you are scanning/looking through source code, the
> "MyVeryVeryVeryVeryVeryUsefulSuperClass::" is irrelevant to you as you are
> more interested in the name of method which is easier to track when it
> starts from the beginning of line and not pushed to the middle of the line
> by the "MyVeryVeryVeryVeryVeryUsefulSuperClass::". For the same reason GNU
> decided to wrap return types. Why would we treat (routine-like in their
> nature) class scope resolutions differently?
>

Several reasons:
- Mostly, readability is about pattern matching. If you are used to things
being formatted like this, it is easier to read for you. If you are used to
different patterns, you find other layouts easier to read. People always
try to make arguments like "this is better because..." (sometimes adding
and "obviously"). And the answer is always: "It is not that simple".
- Vertical space: Readability is usually influenced by how much you can fit
on a screen. If your eyes can easily switch forward and back, e.g. between
a variable declaration and its use, this can help readability in places.
Yes, screens are getting larger, but this remains a factor.
- Easier/more intuitive search: Some people might be used to search for
"Class::Method". Of course you can come up with smarter queries, but this
is what people frequently do. Class name and method name kind of belong
together in some people's eyes.
- ..

However, I am not even trying to convince you to change the coding style. I
just haven't seen it in the wild (and don't know of a public coding style
that recommends it). Yes, it would be a reasonably easy change (although it
would take a few hours taking into account writing decent tests etc.), but
so are most of the others (e.g.
http://llvm.org/bugs/buglist.cgi?product=clang&component=Formatter&resolution=---&list_id=55266plus
hundreds of internal bugs/feature requests). So, it is a matter of
prioritization and this close to the bottom of my list.

Cheers,
Daniel

Regards,
> Alexander
>
>
>
> --
> View this message in context:
> http://clang-developers.42468.n3.nabble.com/ClangFormat-Additional-Options-Proposal-tp4038901p4039163.html
> Sent from the Clang Developers mailing list archive at Nabble.com.
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20140430/353893bb/attachment.html>


More information about the cfe-dev mailing list