Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unify code formating with clang-format? #106

Closed
D4N opened this issue Oct 5, 2017 · 8 comments
Closed

Unify code formating with clang-format? #106

D4N opened this issue Oct 5, 2017 · 8 comments
Labels
enhancement feature / functionality enhancements

Comments

@D4N
Copy link
Member

D4N commented Oct 5, 2017

I have been using clang-format (an automated C/C++/Objective C code formatter) for personal projects and find it very convenient to use, as it ensures that everything is formatted uniformly. It has a lot of options to tweak, so the resulting look can be highly customized (the available options can be found here or seen in action with this handy webpage) but one can also go with one of the presets.

How about we use it for exiv2, too?

@clanmills
Copy link
Collaborator

Let me be sure that I understand what this is. Is this a tool to totally reformat the source code of Exiv2?

I'd like to see this in action on the code base before deciding to adopt this. I assume it will cause a lot of changes to the code layout. Remember that OpenHub monitor our code and I don't want v0.26.1 to contain an "alarming" number of lines of code being changed between v0.26 and v0.26.1.

Perhaps this should be deferred for v0.27 when I believe we're all coming to agree that the major feature of v0.27 is to "modernise the code".

@D4N
Copy link
Member Author

D4N commented Oct 7, 2017

Let me be sure that I understand what this is. Is this a tool to totally reformat the source code of Exiv2?

Essentially yes, although the focus of a clang-format is to ensure a consistent style without the programmers having to actually format the code themselves.

Also, it can be tweaked quite a lot, so as long as the Exiv2 source code is formated consistently, the impact shouldn't be that big. In practice, there will be of course a huge diff as probably no one will go through the hassle of finding the "perfect" configuration.

Deferring this to 0.27 is a sensible choice, if you want to avoid a huge commit. Otherwise we could also start using it gradually, as clang-format can also format only a region of code (at least Emacs' clang-format mode can do that).

There are some big projects using clang-format, for instance Chromium and Mozilla (they have their own builtin styles beside LLVM, WebKit and Google).

@clanmills
Copy link
Collaborator

I think it's a good idea to have a consistent style. The only way to achieve that is to use tools and something based on clang is unlikely to introduce bugs in the C++ code.

It's not the single "huge commit" that bothers me, it's the metric of "lines of code changed = 100%" that bothers me for a "dot" release.

When we start on v0.27, we might even have several "huge commits" if we choose to change our "style template" a couple of times.

What about patches after we've done this. That could create a challenge. That's a strong reason to avoid a "huge commit".

If Pascal is cherry-picking changes on behalf of the distros, we should discuss this with him. Let's do nothing about this at present and discuss it at a team meeting later in the year. We should invite Pascal to the meeting and hear his thoughts.

I wonder if there's anyway to work with "old" and "reformatted" code side by side. We could continue to develop the "old" code, however the published code as been "reformatted". Or that might be a pointless nightmare.

@D4N
Copy link
Member Author

D4N commented Oct 7, 2017

Oh, yeah, cherry picking commits after a huge reformat is going to be ridiculously hard. So maybe let's only do this, if we can find a clang-format config with a small impact.

@piponazo
Copy link
Collaborator

piponazo commented Oct 8, 2017

I also use clang-format in most of my projects and it is very easy to configure and to apply to all the c++ files. We can even do some fancy things once the full project is reformatted, like: adding a CI job forr checking with travis-ci that the format does not differ from our defined style :).

For sure, I also think it is a good idea to wait until 0.27 for this huge change.

@clanmills
Copy link
Collaborator

I think we should approach this with considerable caution. Remember that Exiv2 is open source. It's one thing in the office to reformat code and take the consequences on our shoulders. However we don't know the consequences on our users. In v0.26.1 we could announce that we are considering this for a future release and invite comment. It would be helpful to learn from others who have travelled this road.

Perhaps the v0.27 project should continue to develop the existing code and publish a branch of machine generated reformatted code with the declared intention that v0.28 will be "all new code".

@D4N
Copy link
Member Author

D4N commented Oct 9, 2017 via email

@piponazo piponazo added enhancement feature / functionality enhancements style labels Oct 12, 2017
@D4N
Copy link
Member Author

D4N commented Dec 7, 2017

This has been addressed by #152. I would close this issue then.

@D4N D4N closed this as completed Dec 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement feature / functionality enhancements
Projects
None yet
Development

No branches or pull requests

3 participants