0

Lately my coworker has been on something of a jihad against line counts. When I check in a new file, I'll generally leave all the referenced namespaces that Visual Studio includes, by default (System, System.Collections.Generic, and System.Linq being the majors that I almost always rely on). Several days later, my coworker will be reviewing diffs, see that maybe I haven't actually used any functions from the .Linq namespace, and he'll clip it. When I come back to the file some days later and want to add some functionality that depends on, say, .Select, my blood pressure shoots up when I see that the namespace is gone and I have to add it back.

My question is: aside from the marginal reduction in the project's line count, or the size of the source files, is there any real gain in clipping these unused namespaces? Is the .NET compiler so poor at analysis that unused namespaces induce a penalty in the outputted assemblies? If he's right in pursuing this madness, I'll accept it as a lesson learned... I just can't imagine that there's any sane reason for this. It seems like nothing but boneheaded craziness to me.

Nate Kennedy
  • 383
  • 3
  • 15
  • 4
    No harm in tidying up your namespaces, but it doesn't offer any performance boosts. – Joe Feb 21 '14 at 23:30
  • 2
    As an aside, your collegue might like Resharper. It will show which references are not being used and with one click, remove them. (But as others have noted. Definitely boneheaded craziness.) – crthompson Feb 21 '14 at 23:37
  • 1
    As a minor point, intellisense will fill up with items from included assemblies - this may be irritating to some if the number of unused includes gets out of hand. – J... Feb 21 '14 at 23:38
  • Multiply your colleague's hourly rate by the number of hours wasted by this exercise. Then compare that to the amount of additional profit that this exercise is generating for your company. Which number is larger? It sounds to me like your colleague is not busy enough doing work that generates profits. – Eric Lippert Feb 21 '14 at 23:46
  • View.ShowSmartTag is your friend. – mwilson Feb 22 '14 at 02:32
  • Under threat of public floggings we as a team have agreed that anyone on our team is NOT to remove the default name spaces from a file as they normally have to be added back at some point. Non defaults are fair game to remove if they are not in use. – tsells Feb 22 '14 at 03:35
  • @paqogomez: This feature is already built in to VS2008 and higher. http://msdn.microsoft.com/en-us/library/bb514114.aspx . R# goes a step further and changes the coloring of unused usings, drawing even more attention to them. – Brian Feb 24 '14 at 16:36

3 Answers3

1

Definitely no benefits comparing to the time spent searching and clipping even though VS has an option to do cleaning. No major benefits except compile time benefits and clean coding.

For more info:

Why remove unused using directives in C#?

Community
  • 1
  • 1
Dexters
  • 2,419
  • 6
  • 37
  • 57
  • Thanks for pointing out the dupe - didn't come up in likely matches when I was submitting. Sadly, this is a double-edged sword, as answers go. I can tell him he's not really accruing performance gains - but he can answer back that I'm not improving readability. I hate when answers don't make me the undisputed victor! :) – Nate Kennedy Feb 21 '14 at 23:59
  • 1
    @NateKennedy Readability > Performance gains. And knowing that with ReSharper you can clean them with 1 click, there's no reason not to do it. – Pierre-Luc Pineault Feb 22 '14 at 00:26
0

There won't be any perfomance boost like ou guess, but removing unwanted using is all about keeping your code clean, neat and readable.

Compiler will make use of only required and related assemblies we using in our code.

Make use of visual studio's Remove unused usings command and to remove unused namespaces to make your code lean and readable to another developer also.

ssilas777
  • 9,672
  • 4
  • 45
  • 68
-1

At compile time, only utilised namespaces are compiled into the IL. Those that are unused are ignored.

Aside from a miniscule (and unnoticeable) delay in compilation whilst .Net is figuring out which namespaces you are using there is no impact what-so-ever on the output.

Martin
  • 16,093
  • 1
  • 29
  • 48