开发者

What is the benefit of removing redundant imports in VB.net or using in C# file

I have been using ReSharper for quite a long time and get used to solve a lot of problems by typing Alt+Enter. One of my colleague asked me about the real benefit开发者_运维知识库s and I couldn't say a word apart from that if you are not using it why import it.

Can someone explain what are the real benefits of removing redundant imports if there are eany?


Beside the fact that it cleans up your code, you can also minimize 'name clashes'.
For instance, when you have 2 types with the same name in different namespaces, and you do not use any type from one namespace ... You then do not have to specify the namespace of the type when using it, it keeps your code cleaner.


It removes redundancy, which is a good thing. And its easy to get most of the needed using directives back, by pressing ALT+ENTER (with R#) or invoking the smart-tag by pressing CTRL+. (without R#) on the class that needs it.

On the negative side, you might lose sight of available extension methods, especially when the System.Linq namespace import is removed.


It'll reduce the size of your source code (very slightly), but also improves code quality in my opinion. If you only include what you need, it makes the intent of the file that much clearer.

If you're including a library you don't need, and I'm reading your code, I might end up wasting time trying to figure out where you reference it or why it's used.


If you import more than you need you run into a few issues:

  • When you try to use a class, it is ambiguous which class you mean and you have to specify further to disambiguate
  • Autocomplete suggests many things that you're unlikely to use (it typically does this anyway, but having extra usings just makes the problem worse).
  • It's hard to tell which dependencies your class has just from looking at the using list.


It is faster -- if you have a reference the compiler has to load the symbol tables.


There are no runtime or compilation performance benefits, at all. It just makes for prettier code.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜