Re:Clang-format configurator
by eco on Friday October 30, 2015 @12:42PM
(#10478880)
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.
Re:Clang-format configurator
by eco on Friday October 30, 2015 @10:18PM
(#10481550)
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.
Re:Clang-format configurator
by captainmuon on Friday October 30, 2015 @02:38PM
(#10479662)
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.
Re:Clang-format configurator
by drakenot on Friday October 30, 2015 @12:10PM
(#10478659)
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.
Re:Clang-format configurator
by bigcheesegs on Saturday October 31, 2015 @03:19AM
(#10482081)
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.
Re:Clang-format configurator
by stinos on Friday October 30, 2015 @02:54PM
(#10479771)
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.
Re:Clang-format configurator
by zed0 on Friday October 30, 2015 @03:15PM
(#10479896)
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.
Re:Clang-format configurator
by Cyphus on Friday October 30, 2015 @03:03PM
(#10479824)
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.
Re:Clang-format configurator
by bigcheesegs on Saturday October 31, 2015 @03:22AM
(#10482086)
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.
Re:Clang-format configurator
by rwallace on Friday October 30, 2015 @05:15PM
(#10480581)
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.
Re:Clang-format configurator
by drewm1980 on Friday October 30, 2015 @03:57PM
(#10480162)
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.
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.
[0] https://gist.github.com/mmcdole/e174ba6bede7760cee11
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.