Switching to clang-format reminded me (to a lesser degree though) of the moment when vim finally clicked for me.
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 mapped it to Alt-Space (so I guess it'd be buttons plural) for no other reason than it seemed like a convenient combination for something I'm going to be constantly running.
Incredible coincidence, I used clang-format today for the first time and was looking for such a tool. The one I found had no preview so I just tried a few built-in styles and picked one that was close to my style.
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.
My team recently switched from Uncrustify to Clang-format for our iOS development and this replaces a gap that I had: UncrustifyX.
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.
There's a hard rule for clang-format to only change white space so as not to accidentally make semantic changes. There is however another tool, clang-tidy, for that use case.
Even though we've had a clang format file for a while this is still nice to have, and pretty well done as well. Now I'd just wish clang-format would allow formatting C++ constructor initializer lists like
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.
Thanks for the feedback.
This is one of my (and my work mate's) most wanted features of clang-format. I'd like the ConstructorInitializerAllOnOneLineOrOnePerLine option to break before the first argument too, similarly for arguments etc.
clang-format uses clang's C++ parser to get a real understanding of the code, even in syntactical edge cases. Because of this, clang-format can provide more specific and contextual style rules that go beyond what astyle can do.
clang-format actually only uses clang's lexer, it does its own parsing. It does this so that it can be applied to code snipits and so that you don't have to provide the full include paths and command line options required to correctly parse the file.
In my experience, clang-format is much more usable in practice because it understands more of the syntax of C++ (rather than just relying on heuristics/pattern-matching) so it's much less prone to getting edge cases wrong.
Also hooked on clang-format as of a few weeks ago. It does bizarre stuff sometimes, but I have decided to stop caring. IMHO C++ syntax is so byzantine, if you're capable of groking it at all, you're capable of seeing past white space differences. High time it went viral!
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.