I am using StyleCop for a quite a while (and I am used to it). Friend of mine recommended me to also try CodeMaid. First thing I've noticed is difference in usings organisation.
Stylecop orders usings in alphabetical order where System usings are listed first and non-system usings are listed below.
CodeMaid orders usings also in alphabetical order but it does not order System usings first. It only orders usings alphabetically
Another thing I came across is that CodeMaid allows you to have usings outside of namespace (and as far as I know it is better to place all the usings within the namespace)
I wanted to ask what is the proper ordering of usings and eventually why?
Disclaimer: I wrote CodeMaid.
You can easily change this back to the VS2010 default at Tools->Options->Text Editor->C#->Advanced->"Place 'System' directives first when sorting usings". CodeMaid respects the Visual Studio defined preference which defaults to not putting System directives first.
Hope it helps. :)
There is no "proper" ordering, just conventions. Stylecop's SA1210 rule explicitly states that System
namespaces are placed first:
A violation of this rule occurs when the using directives are not sorted alphabetically by namespace. Sorting the using directives alphabetically makes the code cleaner and easier to read, and can help make it easier to identify the namespaces that are being used by the code. The System namespaces are an exception to this rule and will always precede all other namespaces. See SA1208 for more details.
Rule SA1208 states that the System
namespaces must be before other namespaces, and the reasoning is:
Placing all System using directives at the top of the using directives can make the code cleaner and easier to read, and can help make it easier to identify the namespaces that are being used by the code.
Stylecop's rules are conventions, and Codemaid chose a slightly different convention. Pick the one you like and move on to more important decisions.
See this question regarding having using
statements outside of the namespace.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With