I know VS2008 has the remove and sort function for cleaning up using directives, as does Resharper. Apart from your code being "clean" and removing the problem of referencing namespaces which might not exist in the future, what are the benefits of maintaining a "clean" list of using directives?
Less code?
Faster compilation times?
For me it's basically all about less noise (plus making Resharper happy!).
I would believe any improvement in compilation time would be minimal.
If you always only have the using directives that you need, and always have them appropriately sorted, then when you come to diff two versions of the code, you'll never see irrelevant changes.
Furthermore, if you have a neat set of using directives then anyone looking at the code to start with can get a rough idea of what's going to be used just by look at the using directives.
There's no runtime impact. It's purely compile time. It potentially impacts the following:
- Less chance for Namespace collisions
- Less "noise" in the code file
- Very explicit about which namespaces and possible types to expect in the file
- Using the menu to remove unused and Sort means more consistency with using statements among the devs. Less chance of dumb checkins just to fix it up.
For me, a clean list of using statements at the beginning can give a good understanding of the types to expect.
I saw a decent gain in compile time a few years ago when I first installed ReSharper (on an 18 project solution). Since then its just been about keeping it clean.
I can't speak to the benefits in compile time and performance, but there's a lower chance of namespace collisions if you have minimize your using declarations. This is especially important if you are using more than one third party library.
There is one compile-time difference: when you remove a reference, but still have a using directive in your code, then you get a compiler error. So having a clean list of using directives makes it a little bit easier to remove unused references.
Usually the compiler removes unused references, but I don't know if that works when a using is in the code.