OK, so I know that I should embed my code in namespaces to handle name collisions.
E.g.
My-Header-Only-Library.hpp
namespace AG {
namespace My_Header_Only_Library {
class Foo {
...
};
}
}
So I have AG::My_Header_Only_Library::Foo.
Yes, I often use two levels – the first, variously AG, AFG, libAG, etc. – for “my” stuff (I have maintained some of these libraries for decades, e.g. Valid<T>).
And I often have sub-namespaces for various modules.
PROBLEM #1: namespace names sometimes collide.
Yes: I have found collisions for all of the namespace names AG, AFG, libAG. Yes, I have run into companies that have the same initials as me.
(For a while I used GLEW, thinking that this is a fairly unique last name. Back then I was the only Glew on the internet, and only the 48th person with the initials AG on ARPAnet. (AG48). But since then, OpenGL Extensions Wrangler has pretty much taken that away from me.)
I suppose that “namespace AG_some_random_stuff_675567” is less likely to collide. Is that what people do? Use some long namespace name, and then a
using AG_lib = AG_some_random_stuff_675567
Or do you ever try to play tricks like #defining the name of the namespace to something else.
E.g.
#define AG something_more_unique
PROBLEM #2: I sometimes give, loan, allow companies to use my libraries. Bit I ask that they give changes back, i.e. that they do not fork.
Their coding conventions may not be the same.
I don’t want them to change the namespace names, because that makes pulling their changes back harder.
Q: What to do? Have them do
using Their_Name = AG_some_random_stuff_675567
I usually start with something about what the namespace contains, my full name, and the creation date — in theory this isn’t 100% immune to collisions either, but it’s pretty close1. If you really want something a lot closer to immune, you can generate a GUID and use that instead.
Then, of course yes, there’s a much shorter alias for most normal use. Unfortunately, you can’t always use an alias in place of the full namespace name, but such is life.