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

NL.n Use namespaces, do nest your namespaces. Do not use a suffix or prefix in all defined names to provide scope. #497

Open
SimonTemplate opened this issue Jan 12, 2016 · 23 comments
Assignees
Labels

Comments

@SimonTemplate
Copy link

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 ?

@SimonTemplate SimonTemplate changed the title NL.n Use namespaces, do nest your namespaces. Do NOT use a suffixor or prefix in all defined names to provide scope. NL.n Use namespaces, do nest your namespaces. Do not use a suffix or prefix in all defined names to provide scope. Jan 12, 2016
@Pazns
Copy link

Pazns commented Jan 12, 2016

Do not follow the java path and start using DNS names, or any other global names.

Can you be clearer :-) ?

@SimonTemplate
Copy link
Author

@Pazns, I edited the line and tried to be clearer, hope it worked.

@LegalizeAdulthood
Copy link

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).

@SimonTemplate
Copy link
Author

@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.

@LegalizeAdulthood
Copy link

@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.

@Pazns
Copy link

Pazns commented Jan 13, 2016

@SimonTemplate Yeah, thanks.

What is the idea behind this convention, by the way ?
What if a company doesn't have a domain name ?
How could namespaces benefit from a link with a domain name hierarchy like this ? Even if said namespaces don't exist ?

@SimonTemplate
Copy link
Author

@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.

@Pazns
Copy link

Pazns commented Jan 13, 2016

@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.

@SimonTemplate
Copy link
Author

@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.

@hpesoj
Copy link

hpesoj commented Jan 15, 2016

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.

@SimonTemplate
Copy link
Author

@hpesoj Well, assuming a reasonable number of libraries, I suppose it will work.

@grahamreeds
Copy link

In Java (and .Net) it is natural to have nested namespaces and resulting
deep file hierarchies. It is only unwieldy in C++. And even then you don't
have to nest your file structure.

In fact the only thing that makes it unwieldy is the inability to easily
nest namespaces.

Ie:
namespace foo { namespace bar { namespace stein {

As opposed to

namespace foo::bar::stein {

GR

Sent from my Nexus 5.
On 13 Jan 2016 10:08 a.m., "SimonTemplate" [email protected] wrote:

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.


Reply to this email directly or view it on GitHub
#497 (comment)
.

@LegalizeAdulthood
Copy link

I thought the N4230 proposal for nested namespaces was on track for C++17?

@grahamreeds
Copy link

But not currently standard.

Sorry for derailing the conversation slightly.

Sent from my Nexus 5.
On 19 Jan 2016 21:30, "Richard Thomson" [email protected] wrote:

I thought the N4230 proposal
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4230.html was
on track for C++17?


Reply to this email directly or view it on GitHub
#497 (comment)
.

@LegalizeAdulthood
Copy link

@grahamreeds Agreed, not currently standard.

@SimonTemplate
Copy link
Author

SimonTemplate commented Jan 20, 2016

Yes, nested namespace definition is welcome.

@AndrewPardoe
Copy link
Contributor

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.

@SimonTemplate
Copy link
Author

SimonTemplate commented Oct 21, 2016

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.

@AndrewPardoe
Copy link
Contributor

Assigning to Bjarne. To catch you up, we're looking at adding a note in SF.7 as the preferred option.

@SimonTemplate
Copy link
Author

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.

@JohelEGP
Copy link
Contributor

JohelEGP commented May 7, 2018

Related: https://wg21.link/P0816 (No More Nested Namespaces in Library Design).

@MikeGitb
Copy link

@JohelEGP: Any Idea, how this was received by the committee? Apparently ranges are getting their own nested namespace instead of being put into std2.

@JohelEGP
Copy link
Contributor

I don't remember having read on how they received it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

9 participants