[RFC] Formatting our .c and .h files with clang-format
gregory.szorc at gmail.com
Wed Sep 23 23:15:52 CDT 2015
On Mon, Sep 14, 2015 at 3:03 PM, Augie Fackler <raf at durin42.com> wrote:
> http://clang.llvm.org/docs/ClangFormat.html is a handy tool for having
> a machine format your (C/C++/etc) source code rather than having
> error-prone humans perform the same tasks. Right now we've got a
> handful of rules in check-code for this, but they're not actually
> sufficient for all our code to be substantially similar style. I've
> created a clang-format file that is *close* to what we already do
> (http://hg.durin42.com/hg-wip/rev/aaeda7971cdb) and have wired up
> tests etc that would let us keep files formatted. As a sample of the
> result, I've reformatted:
> * manifest.c: http://hg.durin42.com/hg-wip/rev/ca90a7cff2e1
> This is a nice comprehensive example, and includes working around the
> formatter in a couple spots where Python's macros fool the formatter.
> base85.c: http://hg.durin42.com/hg-wip/rev/177e9d2e3cc5
> This is a nice example of a file that was in its own style that is
> brought in line with the rest of the codebase.
> Note that the resulting code tweaks check-code's "don't use spaces to
> indent" check. My opinion there is that if we start using clang-format
> we should just drop anything in check-code that conflicts with
> clang-format, since the latter is trivial to apply.
I'm a huge fan of having tools do work for me.
When I was hacking on some of the C code a few weeks back, I found the
style a bit foreign. I would have much preferred to write code in my own
style and have clang-format reformat it for me so I didn't have to expend
the cognitive load (beyond naming and calling conventions) to conform to
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Mercurial-devel