[Lint] One parameter/argument per line for C++ code#22725
[Lint] One parameter/argument per line for C++ code#22725kfstorm merged 7 commits intoray-project:masterfrom
Conversation
|
Hmm, personally I think the ugliness is a bit much if the problem could be solved in other ways. Maybe this is a sign we need narrower / cleaner interfaces in Ray for bits that need to be extended, or more components should be upstreamed? |
|
I think the original one seems better. Not sure, but for things like this: to be formatted like this: seems really wired. I checked gRPC and tensorflow and they are not using this one and I'm not sure whether they have similar issues like the one described or not. It seems like other things are not working well, like what Eric mentioned. I'll vote readability over the things mentioned in the descriptions. |
|
I tried these style options a few months ago, and I didn't go through each change one by one. I agree this PR includes some unnecessary changes. We just want to raise the issue of long parameter lists. Ideally, we can upstream more code (we've planned) and refine interfaces, but it's not a thing that can be done within months. I like the idea to put parameters one per line if they can't fit into a single line. Consider changing this local_raylet_client_ = std::make_shared<raylet::RayletClient>(
io_service_, std::move(grpc_client), options_.raylet_socket, GetWorkerID(),
options_.worker_type, worker_context_.GetCurrentJobID(), options_.runtime_env_hash,
options_.language, options_.node_ip_address, &raylet_client_status,
&local_raylet_id, &assigned_port, &serialized_job_config, options_.startup_token);to local_raylet_client_ = std::make_shared<raylet::RayletClient>(
io_service_,
std::move(grpc_client),
options_.raylet_socket,
GetWorkerID(),
options_.worker_type,
worker_context_.GetCurrentJobID(),
options_.runtime_env_hash,
options_.language,
options_.node_ip_address,
&raylet_client_status,
&local_raylet_id,
&assigned_port,
&serialized_job_config,
options_.startup_token);The latter one is way more readable and maintainable to me. I really want to know your opinion about formatting style. Maybe you can reply with a number:
|
|
Regarding readability and aesthetics, I agree that some changes in this PR are not ideal. IIRC, Python's rule is that if all parameters can fit into a single line, put them in a single line, otherwise put each in one line. If we can adopt the same rule, I think this PR can improve code readability. And the amount of changes should be much less. @iycheng will this address your concern? Regarding code conflicts, we are indeed reviewing all existing diffs and planing to upstream as many existing diffs as possible throughout this year. If we could improve this format issues, it would greatly facilitate the process. Last but not least, I'd like to emphasize the benefit of clean git history again. I'v seen such cases many times. It was very inconvenient to git blame the real commit. |
|
I'm not 100% sure about the rules there. But I think if in the end, for functions which have more than 5 parameters, we can put them line-by-line maybe it's ok. I also think for this case, we probably should do it like: Also, I don't think cpp's style has to be aligned with python's style. They are different languages. |
|
Just my opinion: the python rule sounds good to me (and the clean git blame). Could we apply python rule and update the PR so people can see how it looks in real? Something I came across: https://softwareengineering.stackexchange.com/questions/88485/is-it-a-bad-idea-to-list-every-function-method-argument-on-a-new-line-and-why |
I think this would be ideal, I'm sold on this. |
mwtian
left a comment
There was a problem hiding this comment.
I'm ok as long as it is consistent across the code base for most C++ constructs, and similar to a fraction of other C++ OSS projects.
One disadvantage of the new style is that when reading code, more vertical screen estate will be used for the same amount of information.
.clang-format
Outdated
| BinPackParameters: false | ||
| AllowAllArgumentsOnNextLine: false | ||
| AllowAllParametersOfDeclarationOnNextLine: false | ||
| InsertTrailingCommas: Wrapped |
There was a problem hiding this comment.
This option seems only useful for Javascript? https://clang.llvm.org/docs/ClangFormatStyleOptions.html
There was a problem hiding this comment.
Thanks. I'll revisit all configurations.
.clang-format
Outdated
| AllowAllParametersOfDeclarationOnNextLine: false | ||
| InsertTrailingCommas: Wrapped | ||
| AlignAfterOpenBracket: AlwaysBreak | ||
| AllowAllConstructorInitializersOnNextLine: true |
There was a problem hiding this comment.
Is this consistent, with AllowAllConstructorInitializersOnNextLine to true and other *OnNextLine settings false? folly seems to set BinPack* to false and *OnNextLine to true.
|
Everyone, I've revisited the configurations and simplifed them to avoid unnecessary changes. Simple stats for comparison: The original style and stats: The new style and stats: |
I can't find a configuration to have different formatting behaviors based on the count of parameters. |
|
Nice that we can trim down the formatting rule change and code diff. There are other cost to the change, e.g. deviation from the base Google style, disruption to existing PRs etc. But LGTM if there is consensus on this. |
Why are these changes needed?
It's really annoying to deal with parameter/argument conflicts. This is even frustrating when we merge code from the community to Ant's internal code base with hundreds of conflicts caused by parameters/arguments.
In this PR, I updated the clang-format style to make parameters/arguments stay on different lines if they can't fit into a single line.
There are several benefits:
Related issue number
Checks
scripts/format.shto lint the changes in this PR.