
Clang-format configurator - ingve
http://zed0.co.uk/clang-format-configurator/
======
eco
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.

~~~
sawwit
May I ask which button that is?

~~~
eco
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.

------
captainmuon
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.

------
drakenot
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.

[0]
[https://gist.github.com/mmcdole/e174ba6bede7760cee11](https://gist.github.com/mmcdole/e174ba6bede7760cee11)

~~~
coldcode
Sigh, if only there was a formatter for Swift but the language keeps changing
and no one at Apple finds time to work on this.

------
hedgehog
I've had good success using clang-format for Objective-C projects. Someone put
together a config file that's pretty close to Apple's style:

[https://github.com/haaakon/Apple-clang-
format](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.

------
joosters
Can anyone recommend a code formatter for perl? ('rm' does not count!)

~~~
cauterize
Best option is perltidy [https://metacpan.org/pod/distribution/Perl-
Tidy/bin/perltidy](https://metacpan.org/pod/distribution/Perl-
Tidy/bin/perltidy)

~~~
joosters
Thanks!

------
stinos
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.

~~~
zed0
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.

------
nightcracker
How does clang-format compare to astyle?

~~~
Cyphus
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.

~~~
bigcheesegs
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.

------
ape4
Would if nice if it said what the defaults are.

~~~
zed0
This is on my todo list: [https://github.com/zed0/clang-format-
configurator/issues/1](https://github.com/zed0/clang-format-
configurator/issues/1) If you have any more issues or suggestions please add
them.

------
farresito
Looks great. Thank you. I've been using astyle for quite some time. I suppose
they are very similar.

------
drewm1980
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!

