Click here to Skip to main content
15,867,686 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
what is the advantage of removing unused directives?
Posted
Comments
Sergey Alexandrovich Kryukov 28-Jun-12 15:19pm    
Is it a valid question, what do you thing? I mean, is there a single advantage or even excuse for leaving them?
--SA

Cleaner code is the only obvious one I can think of. Why have lines that aren't needed?
 
Share this answer
 
Comments
Ravindranath.net 28-Jun-12 14:37pm    
Do you think those unused directives occupy the memory?
lewax00 28-Jun-12 14:41pm    
When the program is running? I doubt it, I'm pretty sure they're only used by the compiler to tell it where to look for class when you don't use their full name (e.g. "String" instead of "System.String"). As for storage, it would obviously make the source file a little bigger, but not by a significant amount.
Sergey Alexandrovich Kryukov 28-Jun-12 14:45pm    
Don't even thing about it. Everything unused occupies your memory, and the memory of your colleagues, which is even worse. And eats up attention and development time. And invite bugs and other disasters.
--SA
Sergey Alexandrovich Kryukov 28-Jun-12 14:45pm    
My 5. See also my note in my comment.
--SA
It makes the code look tidier! :laugh:

There are a few practical advantages, but mostly they are pretty minor:
1) It can help to avoid name collision by removing unused namespaces: if a namespace isn't registered with using then the member can't collide with similar names in your code.
2) It can make the compilation very, very slightly faster, because the compiler has fewer namespaces to check through when trying to resolve properties and methods. This became slightly more noticable as V3.0 as extension methods increased the searching required.It's not a noticeable improvement unless your projects are massive and your PC is slow, though!
3) it may mean slightly faster typing since the potential autocomplete list is shorter. Again, not noticeable in practice.

Removing the unused namespaces won't alter in any way the output of the compiler, or change the execution of the compiled program in any way at all.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 28-Jun-12 14:45pm    
Sure, a 5.
--SA
Tim Corey 28-Jun-12 15:05pm    
Well answered. +5
Manoj Kumar Choubey 29-Jun-12 0:50am    
nice
While you application starts building..it loads all the classes,methods that are there in the declared namespaces or the directives...which eats the loader time or the compiler time..so it is good to remove the unused directives

Thanks
www.alacraft.com.au
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900