What are the benefits of maintaining a “clean” list of using directives in C#?

后端 未结 8 1004
予麋鹿
予麋鹿 2021-01-04 04:03

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 referenc

相关标签:
8条回答
  • 2021-01-04 04:15

    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.

    0 讨论(0)
  • 2021-01-04 04:25

    For me it's basically all about less noise (plus making Resharper happy!).

    I would believe any improvement in compilation time would be minimal.

    0 讨论(0)
  • 2021-01-04 04:28

    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.

    0 讨论(0)
  • 2021-01-04 04:30

    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.

    0 讨论(0)
  • 2021-01-04 04:36
    1. Less noise.
    2. Clear expectation of what types are used ("My UI layer depends upon System.Net. Wow, why?")
    3. Cleaner references: if you have the minimal set of using statements, you can cleanup your references. Often I see developers just keep throwing references into their projects, but they never remove them when they're no longer needed. If you don't have anything that actually needs a reference (and a using statement counts), it becomes trivial to clean up your references. (Why would you want to do that? In large systems that have been decomposed into components it will streamline your build dependencies by eliminating the unused deps.)
    0 讨论(0)
  • 2021-01-04 04:39

    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.

    0 讨论(0)
提交回复
热议问题