[Development] Resolving coding style contentions

Philippe philwave at gmail.com
Thu Nov 22 07:54:59 CET 2018


I have been using various c++ formatters since 1995 (first one was C-Vision from Gimpel, pretty
good at that time).
But since I tried clang-format, I don't look elsewhere anymore.
Why? Because its parser is unmatched, and with today's possible
complicated C++ constructs, this is a must-have.

Yes, it is not as much customizable as some other tools, and I can regret
that sometimes, but reliability is prime for me.

For the small story: I use different clang-format settings for class
declarations and the rest of the code.
To achieve this, I have a simple custom C++ parser that identifies code
sections with class declarations: these source code sections are
formatted with different settings (clang-format can be executed to
format custom code ranges).

Philippe

On Wed, 21 Nov 2018 14:57:30 -0500
Matthew Woehlke <mwoehlke.floss at gmail.com> wrote:

> On 21/11/2018 14.35, Elvis Stansvik wrote:
> > Den ons 21 nov. 2018 kl 20:28 skrev Matthew Woehlke:
> > We use the following .clang-format at work:
> > [snip]
> > 
> > I'd say it's Qt/KDE-ish. Certainly not perfect by any means, and yea
> > clang-format can do some quite annoying stuff (the re-flowing you
> > mention).
> > 
> > But for the most part, we just get on with it and live with some less
> > then perfect formatting for some things. All in all it's been a real
> > relief for all involved since we started mandating all code to be
> > auto-formatted, and saves a lot of time at review.
> 
> Sure. I'm not against automatic styling tools, by any means! I just
> wanted to point out that a) clang-format isn't the only plausible
> option, and b) clang-format has shortcomings, especially if the style
> you want isn't quite the style *it* wants.
> 
> For a large project, especially one with a large group of contributors,
> forcibly changing the existing code style can be... problematic.
> 
> > I'll definitely look at uncrustify though, thanks for the tip (and for
> > building it!).
> 
> I'm not the author; just one of the current active contributors.
> 
> However, I do recommend it. It has some faults (but it's also under
> active development and patches are encouraged), however I think it is a
> better tool than clang-format in some ways.
> 
> Clang-format is a tool for dictating *to* you how to format your code.
> If you disagree with it, you are wrong, because clang-format is always
> right.
> 
> Uncrustify is a tool for helping to enforce a style that *you* choose.
> It will enforce as much or as little as you like with whatever
> subtleties you want.
> 
> (Uncrustify is also stupidly easy and quick to build compared to clang,
> which is something to keep in mind if you're expecting developers to run
> it locally.)
> 
> -- 
> Matthew
> _______________________________________________
> Development mailing list
> Development at lists.qt-project.org
> https://lists.qt-project.org/listinfo/development





More information about the Development mailing list