OpenGothic icon indicating copy to clipboard operation
OpenGothic copied to clipboard

Suggestion: Add a .clang-format file

Open lmichaelis opened this issue 2 years ago • 9 comments

While working on #271, I've missed being able to automatically format code to the point that I sometimes just didn't do it. Having a .clang-format file like the one I have in phoenix would make contributing easier and get rid of any ambiguity concerning formatting. You can even test out all the parameters it provides in an online tool :)

lmichaelis avatar Sep 12 '22 18:09 lmichaelis

I' have has a look into it, there is one issue with clang-format that I don't know how to solve: Current code-style is apparently not describable in clang:

if( expr ) {
  code();
  } // <--- how?

And changing code-style to else, mean one huge commit that will destroy git-blame :/

Try avatar Sep 20 '22 21:09 Try

Yeah I think that's not possible. But changing that part of the code style shouldn't be too bad since it mostly just affects lines with closing braces, right? I'm not aware of too many cases where block closing braces are on the same line as some other code.

lmichaelis avatar Sep 21 '22 04:09 lmichaelis

I also think that it would be useful to add a .clang-format, just because CLion does not handle the current style so well.

And changing code-style to else, mean one huge commit that will destroy git-blame :/

This problem is relatively easy to fix, this article describes how https://www.stefanjudis.com/today-i-learned/how-to-exclude-commits-from-git-blame/

Reveares avatar Jan 07 '23 15:01 Reveares

Good point, thanks @Reveares !

There is one more thing I'm wondering about: Maybe there a way to instruct clang-format to format now all things, but few selected ones? Reason for that: I'm not ready drop habit of unusual code-style for brackets

Try avatar Jan 07 '23 20:01 Try

+1 for switching to a more common code style with proper support in IDEs. C++ is difficult enough for me right now. Having to fight against CLion every time I hit Enter is painful.

CReimer avatar Feb 02 '23 19:02 CReimer

Good point, thanks @Reveares !

There is one more thing I'm wondering about: Maybe there a way to instruct clang-format to format now all things, but few selected ones? Reason for that: I'm not ready drop habit of unusual code-style for brackets

@Try I just found this in the clang-format docs: It is possible to use a Git plugin which only touches lines changed in Git. Visual Studio probably has a setting to that effect as well.

You could also just manually run it on files you're comfortable with.

lmichaelis avatar Feb 03 '23 09:02 lmichaelis

I found out @Try s brace style is called Ratliff style. The problem is: Nobody wants that brace style. There is only one tool which supports this brace style. It's called astyle. But it doesnt really work for me either. A lot of other stuff is not supported or just ignored

I tried to set it with CLion and I experimented with clang-format. They both don't support Ratliff style.

Or to summarize: It's an extremely exotic code style that no one wants to support.

But let's set it aside for the moment. There's still a lot of other inconsistencies e.g.

Reference alignment and Pointer alignment: Sometimes left, sometimes right

Or commas. Sometimes there's a space after a comma (as it should be) and sometimes there's none.

CReimer avatar Feb 04 '23 22:02 CReimer

I'd also really appreciate using a more common formatting style. I found it very confusing personally.

PoetaKodu avatar Apr 10 '23 19:04 PoetaKodu

I fear no code. But that style... it scares me.

Seriously, I love this project. However I think that the current code style is just killing the appeal of it for a lot of potential contributors.

EDIT: Also remember that we do not have to reformat everything immediately. Accepting a new style in the PR's is a good step forward imo.

PawelBis avatar Apr 10 '23 19:04 PawelBis