Needs Improvement

Colin Coller's Blog
Posts: 62 | Comments: 156 | TrackBacks: ?

November 16, 2004

How do you organize your code?

Back in July, Richard Lowe asked "How do you organize your code?" I'm asking it again because I'd really like to see what everyone has to say. When we first adopted .NET, it took us a long time to come up with a system for organizing our code that worked for everyone, and it wouldn't have taken nearly as long if we could have looked at what other .NET shops were doing. So, for anyone looking for a system to organize their code, here's what we do:

We have a number of common assemblies that contain our configuration, logging, debugging, performance, data access, time zone, and file formatting (CSV, XLS, SPSS, etc) classes. Each assembly contains one root namespace:

    JTLeigh.Common.Configuration

and is contained in a file named after its root namespace:

    JTLeigh.Common.Configuration.dll

and is organized under a directory named after its root namespace:

    \Components\JTLeigh.Common.Configuration\

Each assembly directory contains source and releases directories:

    \Components\JTLeigh.Common.Configuration\Source\
    \Components\JTLeigh.Common.Configuration\Releases\

The source directory contains the source code for the assembly. We typically use it as our working directory when we're working on new versions of the assembly. We don't version the contents of the source directory outside of VSS.

The releases directory contains the binary releases of the assembly organized under directories named after versions:

    \Components\JTLeigh.Common.Configuration\Releases\2.1.1\

Each version directory contains debug, release, documentation, and snippets directories:

    \Components\JTLeigh.Common.Configuration\Releases\2.1.1\Debug\
    \Components\JTLeigh.Common.Configuration\Releases\2.1.1\Release\
    \Components\JTLeigh.Common.Configuration\Releases\2.1.1\Documentation\
    \Components\JTLeigh.Common.Configuration\Releases\2.1.1\Snippets\

which contain the debug build of the assembly, the release build of the assembly, and any documentation and snippets related to the version, respectively.

We use the same directory structure for 3rd party components, application blocks, etc. We don't bother creating directories that will always be empty.

    \Components\SoftArtisans.OfficeWriter.ExcelWriter\Releases\
    (but no source directory because we don't have the source)

We organize products and tools the same way, only in products and tools folders:

    \Products\JTLeigh.Products.Aichi\
    \Tools\JTLeigh.Tools.CopySourceAsHtml\

We haven't found the distinction between components, products, and tools to be all that important, though, so if we were to do it all over again I probably wouldn't have separate component, product, and tool directories.

Whew!

Now how do you organize your code?

Colin

11:00 PM | Colin

Comments

# RE: How do you organize your code?

Wow, that's organised! My short answer is, in whichever way makes sense.
I usewd to try and build my namespace hierarchy, directories etc...but found it was so fluid that this time was mostly wasted. Now I just work out a basic namespace skeleton,and get on with architecting the app...make a few changes to the skeleton....build...change etc...
Basically I try to follow good OO principles; so determine layers which are loosely coupled, group objects appropriately in namespaces, identify and use patterns appropriately, use best practices for application design, etc.
I am a big believer in refactoring though, so using tools like Resharper lets me stop worrying about a-prori organisation, get on with designing applications based on their requirements, cleaning up and refactoring as I go.
As for the physical directory layout, well I'm all for automation and source-control - I tend to keep snapshots of deployed versions / DBs for testing but on my dev machines I only keep latest versions and rely on my source control systems for managing old code items.

03:11 AM | Scott Galloway

# RE: How do you organize your code?

Phil Haack answered my question on his site:

http://haacked.com/archive/2004/11/22/1661.aspx

and pointed me to "Team Development with Visual Studio .NET and Visual SourceSafe" from the patterns & practices team:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnbda/html/tdlg_rm.asp

There's some excellent stuff there if you're interested.

07:09 PM | Colin