views:

172

answers:

3

I'm working on a project where a mixture of C# (95%) and C++/CLI (5%) are used.

The namespace naming convention I'm aiming for is the good old Company.Technology.Etc.. This works perfectly fine for C#. Now, can I carry this across to C++ classes? I read here that compound namespaces aren't supported in C++.

Am I stuck with the clumsy

namespace Company {
    namespace Technology {
        namespace Etc {
           ...
        }
    }
}

in order to stay consistent?

Is it worth trying to stay consistent?

+1  A: 

Yes, you're stuck with it, see this link. In my opinion it's worth using it as it is more readable and manageable to use namespaces. I normally do so in native C++ also.

Simon Linder
+1  A: 

Arg! We did that here for some code too. I hate that.

Is there seriously any confusion there about who signs your paychecks? What happens when Company gets bought by OtherCorp, or the marketing department decides that Technology will henceforth be known as eTech? How much code will have to be changed?

Generally, I'm anti-use. But in situations like this, where the namespaces should probably never have been made in the first place and you are just saving yourself future code changes, I encourage the following line instead of sticking that huge wart in front of every reference:

using Company::Technology;

Namespaces should generally be created when you have several related classes and objects that you are tempted to stick the same name in their identifier. That way, instead of referring to them as foo_operation and foo_class you do foo::operation and foo::class.

T.E.D.
+1  A: 

To define types in the nested namespace, yes you have to do it as you describe. But to use the types, try namespace CTE = Company::Technology::Etc; , then you should be able to do eg CTE::SomeClass someClass;

tragomaskhalos