views:

281

answers:

6

In the past I've always gone and called my namespace for a particular project the same as the project (and principle class) e.g.:

namespace KeepAlive
{
    public partial class KeepAlive : ServiceBase
    {...

Then from other projects whenever i've called that class its always been:

KeepAlive.KeepAlive()...

I'm now beginning to think that this might not be such a good idea, but I'm sort of stumped what to actually call my namespace. What do other people do? Do you just have one namespace for all your projects?

+3  A: 

i name my namespaces with the common descriptor of all the things that go into that namespace.

Mladen Prajdic
+7  A: 

Having the name of a class being the same as the namespace is a bad idea - it makes it quite tricky to refer to the right thing in some cases, in my opinion.

I usually call the project (and namespace) an appropriate name and then have "EntryPoint" or "Program" for the entry point where appropriate. In your example, I'd probably call the class "KeepAliveService".

Jon Skeet
+7  A: 

We have this simple scheme:

  CompanyName.ProductName

Then the application layer, e.g.

  CompanyName.ProductName.Data
  CompanyName.ProductName.Web

etc.

And inside divided per module and/or functionality, which normally correspond to folders

  CompanyName.ProductName.Web.Shop
  CompanyName.ProductName.Web.Newsletter

etc.

BTW: You can find answers to similar questions here:

splattne
We're extremely similar. +1!
John Rudy
What happens when the company name changes, there is a merger or product name changes? If you think it wouldn't be worth changing it int that case, why introduce irrelevancies into the namespace int the first place?
MatthewMartin
I'm using a lot of third-party assemblies. I am very happen that most of them use their company name in the namespace to avoid collisions between them. If yu change your product name, I'm sure there are more things to do and you'll have to refactor many things.
splattne
+4  A: 

CompanyName.ProductName.AreaOfSystem.SubAreaOfSystem

Never call them the same name as a class.

Our areas include things like:

  • Services
  • Smartcard
  • UI

Sub-areas are used sparingly but when relevant:

  • Smartcard.Mifare
  • Smartcard.DESFire

Ours don't correspond to folders because logically that may not be the case. To ease solution explorer navigation we might section off certain bits in folders but that doesn't necessarily mean the namespaces should follow the folder structure. Especially if there are only a few files in the folder (a namespace with few types is usually silly).

Quibblesome
A: 

I like the java package way: com.stackoverflow.Data (or whatwever the primary domain name of your company may be).
That way your namespaces won't be ambiguous.

EricSchaefer
A: 

we stick to the old

uk.co.company.system.layer

scheme that way we keep collisions down to a miniumum as we use a lot of MS Server products and it helps conceptual seperations.

eg.

uk.co.acme.biztalk.bizutils.