8

I'm going to create a new library that renders genome annotations into charts. However, as C++ doesn't have a centralized library website like Perl, how do I know if the namespace conflicts with any existing one?

13
  • 6
    Why not name it XnoDraw::, then?
    – user529758
    Commented Aug 4, 2013 at 9:23
  • 2
    xd make it sound like an internet meme lol::, rly:: and yolo::, XnoDraw:: is better in my opinion, the only thing to notice is that often times names are patented or protected by the law, so be sure to pick a name that is "free". Commented Aug 4, 2013 at 9:30
  • 2
    To close voters: this is neither subjective nor off-topic. Finding a unique name for a library is part of library design, and there are language usage issues here too. Commented Aug 4, 2013 at 11:04
  • 3
    @Potatoswatter: it's pure marketing, it has absolutely nothing with the design.
    – Sergey K.
    Commented Aug 4, 2013 at 11:07
  • 1
    @Potatoswatter: Then the best option to avoid namespaces collision is to generate a 128-bit GUID for it. Why nobody does it?
    – Sergey K.
    Commented Aug 4, 2013 at 11:50

2 Answers 2

12

No, xd is not a good name: it's too short. It could be a good alias in a limited context, but for a library that will be used by others, provide a long, descriptive name. Then users can select an alias that makes sense for their project.

namespace my_company {
namespace XnoDraw {
// ...
} // namespace XnoDraw
} // namespace my_company

// user code, not your code:
namespace xd = my_company::XnoDraw;
1

You could use anything except std.
Note that c++ doesn't allow compound names for namespaces.

For instance:

// Allowed
namespace a
{
    namespace b
    {
        int c;
    }
}

// Not allowed
namespace a::b
{
    int c;
}
1
  • 3
    You have to write namespace twice to open two namespaces, but the set of available names is the same either way. Commented Aug 4, 2013 at 11:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.