views:

622

answers:

2

Hello:

I like trying to stay organized when developing, grouping related *.cs flies together into their own folders:

->Project
--->Enums
--->Exceptions
--->Extensions
--->Providers
--->Configuguration
--->Design
--->etc.
  Manager.cs

As you all know, Visual Studio, by default, creates a new Namespace for each folder:

Company.Product.Enums.MyEnumClass.cs
...
Company.Product.Exceptions.ExceptionBase.cs
etc.

Which has pros...and cons.

The good side is that with intellisense, it becomes trivial to figure out how an assembly was designed: you see all the parts, and only the parts you want (compared to having every single class, enum, static extension clases, business entity, manager, provider, etc. all in one namespace.

The downside is that...you end up having to use a real pile of includes to get coding.

using Company.project.Enums;
using Company.project.Model;
using Company.project.Extensions;
...
etc.

And this way of working has problems...which become most glaring with Extensions...It's one of those cases where it becomes clear that the way I'm going about this is not great (so easy to forget to include using Extensions, and not know that there were already methods to do what I wanted...)

So...on one hand, there is the option of staying organized the way I've been doing for years, and allowing Intellisense to be the way that a new user of an assembly quickly gets up to speed with its functionality, and just lump it for the includes..., the other way is to put everything in one namespace...and write good docuementation on how to get started with the assembly... (more cost/and honestly, might never get done for small projects, etc.)

The official MSDN documentation on Namespaces doesn't give advice on which way to go: http://msdn.microsoft.com/en-us/library/893ke618(VS.71).aspx

THerefore, before I change my ways, I'm very interested in what others are doing, and why...what are you doing, and why exactly?

+7  A: 

I think you're organizing it incorrectly. Don't organize by what enum/extension, etc. Organize by how the type is used. Put related types together.

Also, the guidelines you referenced are from the days of .NET 1.1! The clue is the V7.1 in the URL. The correct reference is Names of Namespaces, which is part of Design Guidelines for Developing Class Libraries.

John Saunders
Hi John:Thanks for the updated links, which does expand on the subject, atleast a smidgeon.It appears that everything should get lumped together...And sometimes that leads to a lot of classes in one namespace.Consider even a trivial example, one dll:* Business Entities,* The Interfaces, that they BizEntities implement...* Enums used for BE properties* Exceptions raised when setting properties* Extensions to the BE's...I havn't even talked about different functionality/groups here. Just one. And yet easily can lead to 80+ classes in one namespace.Comments?
No, everything should _not_ be lumped together. It should be organized by functional area of the code - just not by what sort of type it is.
John Saunders
Hi John:Thanks again. I'm having a little trouble understanding what you consider functional boundaries. If one has an assembly that is meant for handling Messages, and its following Provider factory, how would you break it up?It's all dealling with common Entities (Message, Attachment, Address, Headers), raises common MessageExceptions, uses common Enums (MessagePriority, Importance, etc.), and one MessagingManager + several Providers (LLBLGenBasedProvider, InMemProvider, etc.)It's all one area of functionality: Messages. .. Lump together, or break in sub-NS's? And if so, what/where?
I think I'd put the providers in a separate "Providers" namespace, along with any types that are only used by providers. This would be similar to how .NET Framework puts Designers in a separate namespace from the classes they design for.
John Saunders
But all the others in the same 'base' Manager's namespace? So the boundary you are using is 'core subject=messages=all same NS, including BE's, Event delegates, Exceptions, Enums, Extensions related to core subject'. Plus a sub NS for base classes that potentially 3rd party implementaitions of Core subject... Is that correct?
A: 

What about looking at how the Microsoft-provided frameworks you're using are organised?

Are they easy to work with? Do most people consider them a good exemplar?

frou
Hi frou:In most cases, the NET Framework is very well laid out. Collections, Designers, IO, etc. all have logical namespaces matching functionality.That said, there have been times, when Intellisense has not been enough to deduce how to move forward. One area I remember feeling lost in at first were ASP.NET 2.0 Provider Factories: where the Manager and Providers AND the Config elements that described them, were all in one NS. After much documentation reading, things became clearer...But its one area, Intellisense let me down. Hence my search to do better :-)