-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
NL.n Use namespaces, do nest your namespaces. Do not use a suffix or prefix in all defined names to provide scope. #497
Comments
Can you be clearer :-) ? |
@Pazns, I edited the line and tried to be clearer, hope it worked. |
This feels like many recommendations disguised as a single recommendation. For guidance, I'd prefer to see a single recommendation for each point instead of lumped all together. The "don't use DNS names" for organizing namespaces is sure to find some push-back particularly when coupled with the idea of using github to create yet-another-global-ad-hoc-registry for which the DNS already serves (which is why Java adopted that in the first place). |
@LegalizeAdulthood well I agree, but as there are a number of subheaders in the rule template I got into adding more opinions, maybe I should split into a number of distinct recommendations. |
@SimonTemplate It's fine for it all to be lumped together as items discussed in the issue. A pull request should split out the separate concerns. |
@SimonTemplate Yeah, thanks. What is the idea behind this convention, by the way ? |
@Pazns Do NOT use reversed Internet domain names as a namespace hierarchy, is the idéa. I.e.there is no need for any domain names. |
@SimonTemplate Sorry it wasn't very understable, I was asking about this Java convention totally aside your proposition for the guidelines (with which I agree). Is there any reasons for this DNS-style naming ? It seems a weird choice to me, bringing confusion of meaning if a real domain name hierarchy doesn't exist. |
@Pazns I suppose it's piggybacking on this DNS global naming authority, there are not many such authorities available. But the names contains too many levels and as Java also mirrors this into the folder structure it is rather unwieldy, IMHO. |
I think trying to allocate top level namespaces would probably create more problems than it solved. If two popular libraries which are likely to be used together have conflicting namespaces, they can resolve it between themselves. And I can't imagine this happening all that often. |
@hpesoj Well, assuming a reasonable number of libraries, I suppose it will work. |
In Java (and .Net) it is natural to have nested namespaces and resulting In fact the only thing that makes it unwieldy is the inability to easily Ie: As opposed to namespace foo::bar::stein { GR Sent from my Nexus 5.
|
I thought the N4230 proposal for nested namespaces was on track for C++17? |
But not currently standard. Sorry for derailing the conversation slightly. Sent from my Nexus 5.
|
@grahamreeds Agreed, not currently standard. |
Yes, nested namespace definition is welcome. |
This maybe shouldn't be its own guideline. We have a rule about header files--SF.7. Do we want to make a note about nesting as well as a note under this rule? The rule about do not use suffixes or prefixes should be a note under the naming rules. |
Yes and agree. This is not that major, more a convenience when digesting other peoples code. Second thought: scopes, as by namespaces are not always in header files. I think this is about naming and scopes. |
Assigning to Bjarne. To catch you up, we're looking at adding a note in SF.7 as the preferred option. |
Great news. I am all for coding styles aimed at easing maintenance of large code sets, now only trying to promote this a bit more. |
Related: https://wg21.link/P0816 (No More Nested Namespaces in Library Design). |
@JohelEGP: Any Idea, how this was received by the committee? Apparently ranges are getting their own nested namespace instead of being put into std2. |
I don't remember having read on how they received it. |
Reason:
Provides a narrow context where defined names are short, external names are well marked and also naturally segments your header-files, this makes larger code sets more easy to browse and comprehend and aids with refactoring.
Chances are your IDE provides a folding mechanism for namespaces, which is great when browsing these larger pieces of code.
Examples:
Alternatives:
Exceptions:
extern “C”
Enforcement:
Lint defined names and suggest shortening of long names, find repeated prefixes.
See also:
Notes:
Do not use reversed Internet domain names as namespaces, as java frequently do for package names.
Discussion:
Maybe GitHub could be persuaded to provide a global top-namespace allocatioin mechanism ?
The text was updated successfully, but these errors were encountered: