Namespaces

J

Jefffff

What is a good rationalle for creating namespaces? Please understand that I
know what they are... I'm just wondering when it would make sense to group
my types into multiple namespaces. I see that Visual Studio thinks that
placing files into folders means that everything in a folder should be in
its own namespace and automatically modifies the namespace to include the
folder name. That seems rather arbitrary.

Thoughts? Opinions? Perspective?

Thanks!
 
M

Mythran

Jefffff said:
What is a good rationalle for creating namespaces? Please understand that
I know what they are... I'm just wondering when it would make sense to
group my types into multiple namespaces. I see that Visual Studio thinks
that placing files into folders means that everything in a folder should
be in its own namespace and automatically modifies the namespace to
include the folder name. That seems rather arbitrary.

Thoughts? Opinions? Perspective?

Thanks!

Well, looking at the framework should give you some idea of how a namespace
scheme could be:

All web related stuff goes under Web.
All windows forms related stuff goes under Windows.Forms.
All database connectivity or data access stuff goes under Data.

etc.

I would suggest that you pick a root namespace (first namespace name) and
stick with that as your root (your company name, nickname, or abbreviation,
would be a good start). From there, determine the different major sections
that your classes may be (Web, Windows, Data, etc). Having a namespace of
"Misc" or "Other" isn't recommended (by me at least). Instead, create a
separate namespace for each miscellaneous item that may not fit (such as
MySearchLibrary could go under <companyName>.Data.Search instead of
<companyName>.Data.Misc).

HTH,
Mythran
 
B

Bruce Wood

I use namespaces for layering.

My data layer is the Data namespace. My business layer is in the
Business namespace. I have an extra namespace called
Business.Validation for classes that do user input validation /
management.

Then each application (each UI) has its own namespace, which is what
Visual Studio does by default.

BTW, I find VS's approach just fine. Really you should be fretting over
namespace names only for shared components. For applications, just make
the app name the namespace.
 
P

Peter Rilling

One simple question, do you have every file on your hard drive immediately
under the C:/? If not, then why?
 
M

Michael A. Covington

Peter Rilling said:
One simple question, do you have every file on your hard drive immediately
under the C:/? If not, then why?

D'oh... because, uh, because FAT32 only allows 256 files in a root folder?
:) :) :)
 
M

Mythran

Michael A. Covington said:
D'oh... because, uh, because FAT32 only allows 256 files in a root folder?
:) :) :)

The sub-folder name is C:\FolderDueToFAT32Limitation?

:p

Mythran
 
B

Bruce Wood

The OP wasn't asking why namespaces exist. He knows why. He's asking
what regimen / criteria people use for deciding when to put something
in a new namespace and when to lump it in with other stuff.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top