views:

242

answers:

4

I had to figure out a way to ask this that wasn't subjective, so this is specifically for Microsoft's coding style. In the ASP.NET MVC source, code files look like this:

// Copyright info

namespace System.Web.Mvc {
    using System;

    // blah blah
    // ...
}

Note that 'using System' lines up nicely with the namespace. If I was to apply this style to my company's code, should I put 'using' statements for my company's namespaces directly below as well (so that it lines up)? When I put 'using' declarations at the top, I usually start with .NET namespaces first, so that's why I'm unsure. For example, should I do this:

namespace MyCompany.MyProduct.Something {
    using System;
    using MyCompany.MyProduct.SomethingElse;
}

or this:

namespace MyCompany.MyProduct.Something {
    using MyCompany.MyProduct.SomethingElse;
    using System; 
}

I'm tempted toward the latter.

+7  A: 

There is no single Microsoft style, although there have been attempts to consolidate their standardizations.

That being said, StyleCop forces all System namespaces to be listed first...

Reed Copsey
Thanks for the prompt answer!
Sam Pearson
+1  A: 

Microsoft StyleCop dictates using System.* first then your custom library namespace (i.e. the first option).

Adrian Godong
A: 

You've got two things going on here.

  1. Alignment - They aren't lining up anything. They're using 4 space indents (the default)
  2. Order of using statements - Typically you will find the system namespaces first. Under that you will find a hierarchy of levels

    using System;
    using System.Collections;
    using System.Collections.Specialized;

Brad Bruce
A: 
Partha Choudhury