Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Finding unused 'Imports' statements in VB.NET source code

The Visual Studio IDE allows me to scan for unused references in VB.NET source code. But I also have a lot of unused Imports statements in my application.

Two questions:

  • Is there a way to find unused Imports statements throughout my VB.NET source code?
  • Do unused Imports statements hurt the performance of my application?
like image 384
Maestro Avatar asked Oct 12 '10 12:10

Maestro


2 Answers

It doesn't hurt runtime performance at all, the only time those using directives are actually used is at compile time.

The three reasons why you could want to keep your import count low are :

  • For clarity sake. Imports are a usefull way to learn at first glance what kind of operations a class is performing : don't waste this opportunity ! (eg if I see a Regex namespace imported on top of a file, I usually assume there's some regex work in it)

  • The more imports you have, the more likely you are to run into a name clash (ie having one type name refering to two different types in two different imported namespaces)

  • Since those directives are used at compile time, having lots of unused import could hurt buildtime and/or intelliSense performance. (Just speculating here, I don't know how IntelliSense is working behind the scenes)

If you want to get rid of those useless namespaces, I don't think there's any built-in support for that in Visual studio (I assume this is what you meant by "the VB.net IDE"), but you can either use some third party tools (eg Resharper) or some other IDEs (eg Eclipse.net)

like image 85
Brann Avatar answered Oct 17 '22 04:10

Brann


I believe this inclusion is done at compile time, and only on demand.

In other words, no performance penalty.

like image 36
torkildr Avatar answered Oct 17 '22 03:10

torkildr