Code organization, namespaces, components and so forth

When working with Java at least one thing is pretty straight forward. You use packages and they have to map directly to directories on the harddrive. .NET is nicer and allows you to do whatever with sourcefiles, namespaces and project files. This can cause a real mess though, if you don't have a well-thought policy on how it should be done.

I have the past months tried out different approaches in codeorganization, and reviewed some open-src projects for pointers. The practice seem to differ. The crowd using NAnt either organize Java-style or namespace/component style. Last one is usually one folder per component with the full namespacename i.e. "MyRootNameSpace.ComponentName" with each of these folders typically containing a VS.NET solution or project file (or both). Those not using NAnt seem to have their own twist every time.

With the new great feature on GotDotNet Workspaces with VS.NET integration the discussion on how to organize the source is heating up in my current project.

Should sourcefiles be organized like in java and map to the logical namespaces with components and build info (VS.NET projects or NAnt) completely separate or is a component focused approach perferred? Or maybe in an even better way? Another question under debate here is namespace <-> component distribution. Could (or should) namespaces be shared between components?

I'd sure like to see more UML Package, Component and Deployment diagrams (on the same project) from Microsoft Patterns & Practices..

Update:
Paul and Robert gave their input. We decided on a strategy. For greenfield development a small process pattern could look like this:

1. Identify use cases
2. Identify main application components and dependencies
3. Create appropriate projects in VS.NET for each component inside the projects src directory. Naming could be CompanyName.BrandName.ComponentName
4. Set suitable default namespaces for your projects. Logically organized and possibly cross-component.
5. (Optional) Create NUnit testprojects in your src dir. Naming could be CompanyName.BrandName.ComponentName.ComponentNameTests
6. (Optional) Create NAnt build scripts for each project (in each subdir from src) and a master buildfile in the \src root.

 

1 Comment

Comments have been disabled for this content.