Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 34.3k
doc: make C++ core guidelines a reference#24315
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
Uh oh!
There was an error while loading. Please reload this page.
Conversation
joyeecheung commented Nov 11, 2018 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
As our C++ codebase consists of many code that interface with third-party libraries that does not follow the C++ core guidelines, it may be difficult to enforce the guidelines without sacrificing consistency or introducing cruft that juggles with data structures. This patch makes the C++ core guidelines a reference instead of a general guideline to follow to reduce nits that are open to interpretation during code reviews, and highlights the automatic tooling for C++ styles. We may revisit the general priority when there are better automatic tools in place.
nodejs-github-bot commented Nov 11, 2018
refack commented Nov 12, 2018
I'm not in favor of the change as it is, I still think we can benefit for the C++CG. As I see it one of the benefits we get is not needing to explain why we do things when they fit the guide. |
refack commented Nov 12, 2018 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
|
joyeecheung commented Nov 12, 2018 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
Someone still has to read the guide, and rules still need to be interpreted, so without automatic tooling explanations are still needed until we all become good C++ core guideline lawyers (but even then there will be room for lawyering).
I don't think this would be sustainable without automatic tooling. The guideline should serve us, we do not serve the guidelines. If something like this cannot be easily done with something similar to a |
| Google C++ Style Guide or this document. At the moment these guidelines are | ||
| checked manually by reviewers, with the goal to validate this with automatic | ||
| tools. | ||
| In general code should the Google C++ Style Guide, unless overridden by this |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo? should the Google?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(I guess follow is missing in the sentence?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd drop In general if possible. It serves only to make following the style guide seem optional. Even if it is optional, should seems to provide sufficient wiggle-room for those times when you can't follow it.
| are specific to the Node.js C++ code base. This document explains the most | ||
| common of these rules: | ||
| In code that does not interface with any third-party libraries, | ||
| [C++ Core Guidelines][] may be a reference for good practices. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
may be -> are?
refack commented Nov 12, 2018
I've been testing the available tools |
Trott commented Nov 12, 2018
My idea is a generic one, but here you go anyway: Maybe an ad hoc working group (chartered or not)? Like, a small number of active contributors who are particularly active in the C++ code and who want the situation to improve. Have an actual discussion to devise an actual strategy. Prioritize what needs to be done first and how to do it. Also: Leverage Code & Learn and Node Todo to get broadly-supported practices implemented slowly if churn and review-ability of one mega-PR is a concern? |
addaleax left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
fhinkel left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM with comment's from Rich
refack left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I strongly disagree with this change.
refack commented Nov 13, 2018 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
I think this is a regression in the quality standards we strive to achieve. From my recept experience writing and reviewing code for this project, following the C++CG has unequivocally resulted in better code.
@joyeecheung, could you explain? AFAIK guidelines by definition eliminate cruft as they provide objective reasoning for each suggestion. |
joyeecheung commented Nov 13, 2018 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
For example when using the new Local<Value> elements[] ={.... }; Array::New(isolate, elements, arraysize(elements));Following the C++GC as cited here (albeit we were passing it into our own API in that specific piece of code): std::array<Local<Value>, kKnownSize> elements ={.... }; Array::New(isolate, elements.data(), elements.size());The C++CG generally prefers C++ STL containers over equivalent C constructs, but the third-party libraries don't necessarily accept those types - for instance, the new The same can also be said about std::string v.s. We don't necessarily have to go that far, for sure, but making C++CG a hard rule limits our possibilities and that's why I think it should be a reference instead of a law we need to follow and nit-picks with in code reviews. As far as I see C++CG is easier to follow when you are building a C++ project from the ground up, but not when you are gluing many third-party libraries together and have a compatibility burden. |
joyeecheung commented Nov 13, 2018 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
There is a trade-off between regression in code quality and regression in the smoothness of code reviews - IMO we should refrain from nit-picking about stylish issues that do not affect functionality or performance in any significant way in code reviews, and dedicate cleanup patches to them. If we want to enforce a style, that can be automated instead of being enforced by human beings in code reviews, and the styles that can't be automated yet can be dealt with in separate patches. Having too many style nits is not healthy for code reviews, IMO, and it puts an emphasis on human effort when that style cannot be enforced with tooling, which is also unhealthy. We don't need every patch on the master to be perfect, especially in terms of style. As long as the tests pass (that includes linters, and potentially sanitizers when we can turn them on), we can always deal with style issues later. |
refack commented Nov 15, 2018 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
Let take the above example: Local<Value> elements[] ={.... }; Array::New(isolate, elements, arraysize(elements));Modern C++ std::array<Local<Value>, kKnownSize> elements ={.... }; Array::New(isolate, elements.data(), elements.size());We can confirm that both generate exactly the same machine code - https://godbolt.org/z/-_J21G As I see it the first snippet has two issue:
The second snippet has one issue:
The bonus is that we do have "decay" we explicitly have to call As for the smoothness of code reviews, IMHO that is one of the great benefits of this project. It's a place were we all can learn and teach each other. We should celebrate comments that makes us think and reconsider what we are writing. |
bnoordhuis commented Jan 22, 2019
Since @refack's nack still stands, does this need to be put to the TSC? I don't think we actually follow the Core Guidelines all that much so in that respect the style guide is currently at odds with reality. |
refack commented Jan 22, 2019
I'd be happy to hear new perspectives after 3 months. |
bnoordhuis commented Aug 15, 2019
Another six months passed. I would like for this to either go in or be closed out. @refack Do you still have a vested interest in this? |
fhinkel commented Oct 28, 2019
I'm cleaning out a few old PRs 🧹. I'm closing this due to inactivity. Please re-open if needed! |
As our C++ codebase consists of many code that interface with
third-party libraries that do not follow the C++ core guidelines,
it may be difficult to enforce the guidelines without sacrificing
consistency or introducing cruft that juggles with data structures.
This patch makes the C++ core guidelines a reference instead of a
general guideline to follow to reduce nits that are open to
interpretation during code reviews, and highlights the automatic
tooling for C++ styles. We may revisit the general priority when
there are better automatic tools in place.