views:

135

answers:

4

I'm tasked with choosing a name that will in effect be the internal name of our architecture. I'm taking this responsibility seriously, as I have worked with a lot of "bad" namespaces and don't want to inflict one on others.

What makes a "bad" namespace to me?

In terms of human factors:

  • An acronym that is essentially meaningless: DDL, MOS, etc
  • A namespace that collides with a common one from another vendor, like Office or Text or IO
  • A namespace that's difficult to spell or pronounce for non-native English speakers because it's either a foreign word or a proper noun: Vancouver

and so on.

I feel comfortable choosing a namespace in terms of descriptive ability and mnemonic. I'm wondering what the technical consequences of namespace names can be. For instance, what problems might arise from the namespace _, which is a legal C# namespace name? What about a single letter, like e? Are there namespaces that give CodeDom or Reflector fits? Do some namespaces that are legal in C# cause problems in other .Net languages? Is it possible to choose a namespace that is not Mono-compliant for some reason? Have you worked with a namespace that made your life difficult for reasons involving the compiler or Visual Studio or the Windows (or Linux) filesystem?

Thanks for reading and thanks in advance for any help!

A: 

Make sure the namespace starts as uniquely as possible, to avoid the kind of collision you have described. eg:

 YourCompanyName.subnamespace.subsubnamespace
 YourLastName.YourFirstName.subnamespace.subsubnamespace
Oded
A: 

Go with the name of whatever unit you're in within your company

Beth
For what *technical reason*? Something involing the .Net development sysem, not human beings
Chris McCall
None, as far as I know. It's simply the convention. Witness Microsoft, Crystal, etc.
Beth
A: 

Don't try too hard to get it right the first time. No matter how clever or clean you think your naming convention and structure might be you will be renaming and moving things around. That's just how it is.

For starters it's most important to make sure there's low chance of collision in your base name. Later on you will be able to refactor the namespace easily with tools like ReSharper et al.

Paul Sasik
+8  A: 

For non-technical stuff, read the Frameworks Design Guidelines. They have lots of good advice. Briefly:

  • Start with a company name.
  • choose stable (version-independent) names. FrobCorp.FrobozzleV2.Utilities is bad.
  • choose names that reflect the code purpose rather than the politics of the organization that produced it. FrobCorp.AdvancedResearchDivision.CambridgeOffice is bad; the AdvancedResearchDivision might be renamed tomorrow and the Cambridge office might be relocated.
  • use PascalCase unless that violates your branding. FrobCorp.jFrobozzle looks terrible, but FrobCorp.Jfrobozzle looks even worse.
  • use plurals when appropriate
  • and so on.

There is a lot more good advice in the guidelines that I have not reproduced here. Go read them.

However, it sounds like you've got the non-technical stuff down. One of the bits of advice in the guidelines is "do not name a type the same as its namespace". That is good advice not just because doing so is confusing to readers; there is a good technical reason as well.

For the technical reasons why naming a type the same as its namespace is a terrible idea, see my articles on the subject:

http://blogs.msdn.com/b/ericlippert/archive/tags/namespaces/

Eric Lippert
This is a home run answer.
Chris McCall
@Eric: The guideline about not having the same name as the type for a namespace was done often by a programmer here and when I mentioned it several times, I have been looked down by him simply because he has the word programmer in his title. He told me those guidelines are there for the average people, advanced people can break them when they see fit. And added even MS doesn't really use them themselves. Anyway what to do in these kinds of situations where I know the code quality suffers because of ignorance? Because you know once the change is in, it's more risky to change it later.
Joan Venge
@Joan: It is important to know the difference between a "rule" and a "guideline", and to know when is the right time to disregard rules or guidelines in pursuit of a larger goal. That, however, does not make an appeal to authority a sound argument! Microsoft has occasionally violated these guidelines, and many of those violations are noted in the annotated Frameworks Design Guidelines as examples of "why you should never do this, because our mistake caused us a lot of pain". Brad Abrams gives the example of Microsoft putting an organizational detail in a namespace as a cautionary tale.
Eric Lippert
@As for what to do about it: don't change working code without a cost-benefit justification. The risk of the change breaking something might not outweigh the benefit of improving the code.
Eric Lippert
@Eric: Thanks Eric, appreciate your advice.
Joan Venge