Some points on clang-format usage

Miklos Vajna vmiklos at collabora.co.uk
Fri Nov 17 09:54:42 UTC 2017


Hi Stephan,

On Fri, Nov 17, 2017 at 10:03:11AM +0100, Stephan Bergmann <sbergman at redhat.com> wrote:
> Some random points regarding our recently introduced use of clang-format:
> 
> 
> * clang-format cannot automatically reformat code
> 
> Most comments in the code are written by humans, for humans.  They are often
> placed in a way that makes it technically unclear what code they pertain to,
> relying on humans to nevertheless easily discern that.  For example, in
> 
> > void f(int x) { g(x + 1); } // long comment explaining how g internally subtracts one
> 
> the comment clearly pertains to the call to g.  Yet, clang-format will
> reformat this to something like
> 
> > void f(int x)
> > {
> >     g(x + 1);
> > } // long comment explaining how g internally subtracts one
> 
> instead of
> 
> > void f(int x)
> > {
> >     g(x + 1); // long comment explaining how g internally subtracts one
> > }
> 
> thereby obscuring things.  Always review automatically reformatted code for
> glitches like this.

Thanks for mentioning this. I also noticed something similar with
initializer lists, where

Foo::Foo()
    : foo(1), // foo
      bar(2) // bar
{
}

gets reformatted to:

Foo::Foo()
    : foo(1)
    , // foo
    bar(2) // bar
{
}

but the ideal form is probably

Foo::Foo()
    : foo(1) // foo
    , bar(2) // bar
{
}

instead.

Regards,

Miklos
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: Digital signature
URL: <https://lists.freedesktop.org/archives/libreoffice/attachments/20171117/a0296410/attachment.sig>


More information about the LibreOffice mailing list