Skip to content

Conversation

@aheejin
Copy link
Member

@aheejin aheejin commented Apr 23, 2019

While looking at code changes after mass clang-formatting our current
codebase, I think this rather hurts readability than improves it. And
none of preset styles (LLVM, Chrome, Google, Mozilla, and WebKit) allows
these, with only exception that Google allows short ifs on a single
line.

While looking at code changes after mass clang-formatting our current
codebase, I think this rather hurts readability than improves it. And
none of preset styles (LLVM, Chrome, Google, Mozilla, and WebKit) allows
these, with only exception that Google allows short ifs on a single
line.
@aheejin aheejin requested a review from kripken April 23, 2019 23:41
@aheejin aheejin merged commit 7c5a789 into WebAssembly:master Apr 23, 2019
@aheejin aheejin deleted the no_allow_short branch April 23, 2019 23:59
aheejin added a commit to aheejin/binaryen that referenced this pull request Apr 24, 2019
This applies clang-format to the whole codebase. Below are manual tweaks
I had to make:

1. After clang-format changed the order of #includes, the code failed to
compile, so this also adds some missing header guards and more #includes
to make code compile.

2. After applying clang-format to this kind of code,
```
cashew::IString GLOBAL("global"),
                NAN_("NaN"),
                INFINITY_("Infinity"),
                NAN__("nan"),
                INFINITY__("infinity"),
                TOPMOST("topmost"),
                INT8ARRAY("Int8Array"),
                ...
```
This becomes
```
cashew::IString GLOBAL("global"), NAN_("NaN"), INFINITY_("Infinity"),
  NAN__("nan"), INFINITY__("infinity"), TOPMOST("topmost"),
  INT8ARRAY("Int8Array"), INT16ARRAY("Int16Array"),
  ...
```
I fixed the formatting by adding the type to every line as follows:
```
cashew::IString GLOBAL("global");
cashew::IString NAN_("NaN");
cashew::IString INFINITY_("Infinity");
cashew::IString NAN__("nan");
cashew::IString INFINITY__("infinity");
cashew::IString TOPMOST("topmost");
cashew::IString INT8ARRAY("Int8Array");
...
```

3. I fixed many parts of the comments for readability. The most
frequently occurring example was this:
```
SomeClass var = 123; // very very very very very very very very very very very very very very very very long comment
```
clang-format blinds transforms this into:
```
Someclass var
  = 123; // very very very very very very very very very very very very
         // very very very very long comment
```
I fixed these to:
```
// very very very very very very very very very very very very very very
// very very long comment
SomeClass var = 123;
```

4. I ended up using `clang-format off` and `clang-format on` to
explicitly disable clang-format only in one place in
`src/support/safe_integer.cpp`. We couldn't maintain its readability of
the last comment block there.

---

Please let me know if there are any suggestions to this or our current
.clang-format configuration. I tweaked our clang-format setting a bit
more in WebAssembly#1986, WebAssembly#2038, and WebAssembly#2044, but mostly I don't have strong
opinions.

This PR is intended only for code review and should not be merged to the
codebase. After this is reviewed and approved, I ask @kripken to create
a separate PR with the same diff and merge it, not to overwrite the
whole codebase with my username, who is not a very frequent contributor
here.

I also plan to add a hook that checks if the PR is properly
clang-formatted to our Travis CI, but I'm gonna test it in another PR
first.
aheejin added a commit to aheejin/binaryen that referenced this pull request Apr 24, 2019
This applies clang-format to the whole codebase. Below are manual tweaks
I had to make:

1. After clang-format changed the order of #includes, the code failed to
compile, so this also adds some missing header guards and more #includes
to make code compile.

2. After applying clang-format to this kind of code,
```
cashew::IString GLOBAL("global"),
                NAN_("NaN"),
                INFINITY_("Infinity"),
                NAN__("nan"),
                INFINITY__("infinity"),
                TOPMOST("topmost"),
                INT8ARRAY("Int8Array"),
                ...
```
This becomes
```
cashew::IString GLOBAL("global"), NAN_("NaN"), INFINITY_("Infinity"),
  NAN__("nan"), INFINITY__("infinity"), TOPMOST("topmost"),
  INT8ARRAY("Int8Array"), INT16ARRAY("Int16Array"),
  ...
```
I fixed the formatting by adding the type to every line as follows:
```
cashew::IString GLOBAL("global");
cashew::IString NAN_("NaN");
cashew::IString INFINITY_("Infinity");
cashew::IString NAN__("nan");
cashew::IString INFINITY__("infinity");
cashew::IString TOPMOST("topmost");
cashew::IString INT8ARRAY("Int8Array");
...
```

3. I fixed many parts of the comments for readability. The most
frequently occurring example was this:
```
SomeClass var = 123; // very very very very very very very very very very very very very very very very long comment
```
clang-format blinds transforms this into:
```
Someclass var
  = 123; // very very very very very very very very very very very very
         // very very very very long comment
```
I fixed these to:
```
// very very very very very very very very very very very very very very
// very very long comment
SomeClass var = 123;
```

4. I ended up using `clang-format off` and `clang-format on` to
explicitly disable clang-format only in one place in
`src/support/safe_integer.cpp`. We couldn't maintain its readability of
the last comment block there.

---

Please let me know if there are any suggestions to this or our current
.clang-format configuration. I tweaked our clang-format setting a bit
more in WebAssembly#1986, WebAssembly#2038, and WebAssembly#2044, but mostly I don't have strong
opinions.

This PR is intended only for code review and should not be merged to the
codebase. After this is reviewed and approved, I ask @kripken to create
a separate PR with the same diff and merge it, not to overwrite the
whole codebase with my username, who is not a very frequent contributor
here.

I also plan to add a hook that checks if the PR is properly
clang-formatted to our Travis CI, but I'm gonna test it in another PR
first.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants