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

Experiment with clang-format. #356

Closed
wants to merge 2 commits into from
Closed

Conversation

vasil-pashov
Copy link
Collaborator

@vasil-pashov vasil-pashov commented May 9, 2023

The style is based on LLVM. With the following differences:

  • AccessModifierOffset: -2 -> -4
  • AlignAfterOpenBracket: Align -> DontAlign
  • AllowAllArgumentsOnNextLine: true -> false
  • AllowAllParametersOfDeclarationOnNextLine: true -> false
  • AllowShortEnumsOnASingleLine: true -> false
  • AllowShortFunctionsOnASingleLine: All -> None
  • AlwaysBreakTemplateDeclarations: MultiLine -> Yes
  • BinPackArguments: true -> false
  • BinPackParameters: true -> false
  • AllowAllConstructorInitializersOnNextLine: true -> false
  • IndentWidth: 2 -> 4
  • ObjCBlockIndentWidth: 2 -> 4
  • ReflowComments true -> false
  • SpaceAfterTemplateKeyword: true -> false
  • SortIncludes: true -> false // Sorting the includes makes the build to
    fail
  • ColumnLimit: 80 -> 120
  • PackConstructorInitializers: BinPack -> Never
  • PointerAlignment: Right -> Left
  • AfterControlStatement: false -> MultiLine
  • AfterFunction: false -> true
  • BreakBeforeBraces: Attach -> Custom

@jjerphan
Copy link
Collaborator

jjerphan commented May 9, 2023

Thanks for making the formating uniform, @vasil-pashov.

Formatting is useful, yet it can create obfuscation.

We might want to ignore commits in the blame view for GitHub and have people adapt their local setup with blameignoreRevsFile .

What do you think?

@vasil-pashov
Copy link
Collaborator Author

@jjerphan adding a .git-blame-ignore-revs is a great idea. I'll add one.

I didn't get this part, however:

and have people adapt their local setup with blameignoreRevsFile .

cpp/arcticdb/async/async_store.hpp Outdated Show resolved Hide resolved
cpp/arcticdb/async/async_store.hpp Outdated Show resolved Hide resolved
cpp/arcticdb/async/async_store.hpp Show resolved Hide resolved
cpp/arcticdb/async/async_store.hpp Show resolved Hide resolved
@jjerphan
Copy link
Collaborator

@jjerphan adding a .git-blame-ignore-revs is a great idea. I'll add one.

I didn't get this part, however:

and have people adapt their local setup with blameignoreRevsFile .

Oh, I wanted to say that the setup is automatic on GitHub but that it isn't locally.

Locally, one needs to adapt the configuration with:

git config blame.ignoreRevsFile .git-blame-ignore-revs

The style is based on LLVM. With the following differences:
* AccessModifierOffset: -2 -> -4
* AlignAfterOpenBracket: Align -> DontAlign
* AllowAllArgumentsOnNextLine: true -> false
* AllowAllParametersOfDeclarationOnNextLine: true -> false
* AllowShortEnumsOnASingleLine: true -> false
* AllowShortFunctionsOnASingleLine: All -> None
* AlwaysBreakTemplateDeclarations: MultiLine -> Yes
* BinPackArguments: true -> false
* BinPackParameters: true -> false
* AllowAllConstructorInitializersOnNextLine: true -> false
* IndentWidth: 2 -> 4
* ObjCBlockIndentWidth: 2 -> 4
* ReflowComments true -> false
* SpaceAfterTemplateKeyword: true -> false
* SortIncludes: true -> false // Sorting the includes makes the build to
  fail
* ColumnLimit: 80 -> 120
* PackConstructorInitializers: BinPack -> Never
* PointerAlignment: Right -> Left
* AfterControlStatement: false -> MultiLine
*  AfterFunction: false -> true
* BreakBeforeBraces: Attach -> Custom
AsyncStore(std::shared_ptr<storage::Library> library, const arcticdb::proto::encoding::VariantCodec& codec)
: library_(std::move(library)),
codec_(new arcticdb::proto::encoding::VariantCodec{codec})
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Egyptian brackets please.

Copy link
Collaborator Author

@vasil-pashov vasil-pashov Jun 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are basically 3 things we can do:

void function(int param1,
    int param2,
    int param3,
    int param4) {
    //function body
}

Pros: most of the function will stay the same
Cons: When wrapping happens the last param and the function body are indented the same and it's kind of hard to tell where params end and where the body starts

void function(int param1,
    int param2,
    int param3,
    int param4)
{
    //function body
}

Pros: Clear separation between the end of the function params and the start of the body
Cons: Changes each function

void function(int param1,
              int param2,
              int param3,
              int param4) {
    //function body
}

Pros: Provides some separation (not always) between the body and the end of the params.
Cons: (Personal opinion) looks weird. Will change lots of functions

}

folly::Future<entity::VariantKey> write(
stream::KeyType key_type,
folly::Future<entity::VariantKey> write(stream::KeyType key_type,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer: once wrapping starts, the first argument should be wrapped as well.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not possible with clang format as of today.

std::move(segment),
library_,
codec_,
size_t(0)})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really like the original two-line wrapping for this call. When I read that, my brain is able to parse the structure quickly and I can then focus on the important bits.

The long wrapping, on the other hand, robs the focus and I have to triple read to make the connection between submit_cpu_task and via below.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are rare occasions where we don't want to enforce wrapping. If we don't enforce it it will dissolve into anarchy. On the other hand I feel like having multiple things on the same line is confusing and easy to misread.

timestamp creation_ts,
IndexValue start_index,
IndexValue end_index,
SegmentInMemory&& segment) override
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When Egpyption brackets are used, the argument list needs extra indentation to offset it from the function body.

folly::Future<VariantKey> copy(KeyType key_type, const StreamId& stream_id, VersionId version_id, const VariantKey& source_key) override {
return async::submit_io_task(CopyCompressedTask<ClockType>{source_key, key_type, stream_id, version_id, library_});
folly::Future<VariantKey>
copy(KeyType key_type, const StreamId& stream_id, VersionId version_id, const VariantKey& source_key) override
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to prefer wrapping the arguments first instead of the type?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think there's a direct option to this. But you can assign some penalty value, so it prefers putting the type on the same line.

@mehertz mehertz closed this Jul 26, 2023
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.

5 participants