Clang-format configurator
zed0.co.uk
zed0.co.uk
Code formatting is just something I don't do anymore. It's taken care of. I don't waste my time and thoughts trying to make the code look nice and readable. I hit a button and it becomes nice and readable; often nicer than I would have done it by hand. Like vim, when I don't have clang-format available my editing feels very hobbled like I'm typing with my knuckles.
There are probably other great formatters out there but clang-format was the first one that just blew me away with how good it was.
I'm writing a lot of code recently and gently trying to get my colleagues (and myself) to do "best practices" like consistent code formatting, not too long lines, thinking about readability, but also using modern C++11/14 features for cleaner code. We're physicists and mostly not professional programmers so we're a bit behind in some things.
I recently installed YouCompleteMe with vim which really is a game changer - the code completion makes it more pleasant to write in C++(11) than in python (which are the two languages our framework supports), and the error/warning highlighting catches most bugs before compiling. Long story short, for YCM I installed clang, and it comes with a bunch of tools like clang-format. There seems to be a static analyzer which I want to check out, and a tool that finds opportunities to use clearer modern C++11 constructs, pretty nice.
We had a lot of issues with Uncrustify and I burned a lot of time trying to deal with its bugs. Clang-format can't do everything that Uncrustify can do, but I've had a lot less problems with it. The only thing I really miss is Uncrustify would do more than format white-space. It would make code alterations such as inserting missing block braces, etc.
My .clang-format config[0] is also much smaller and understandable as well.
https://github.com/haaakon/Apple-clang-format
Particularly when using features like blocks clang-format does a better job than the other tools we tried.
Foo() :
a( 0 ),
b( 0 )
{
}
which we happen to find the most readable and which afaik is not that uncommon. Just a couple of weeks ago I even looked into submitting a patch but, shame on me, gave up after going throigh the source for an hour or so. It's extremely well written but it was just too much for a quick fix.