472,325 Members | 1,496 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,325 software developers and data experts.

'using' best practices

I was wondering why we have to have
using System.Data
using System.Configuration
using etc....

why are they not all lumped into one 'using'?

In other words, is there a best way to use project classes with 'using'
meaning

is it best to put them all in one folder = no performance hit for doing so
using MyProject.Classes;

or

is it best to put them in different folders to avoid a performance hit by
'using' all of them
using MyProject.Classes.This;
using MyProject.Classes.That;
using MyProject.Classes.Other;

Thank you
Nov 17 '05 #1
3 2317

"xzzy" <mr********@comcast.net> wrote in message
news:hZ********************@comcast.com...
I was wondering why we have to have
using System.Data
using System.Configuration
using etc....

why are they not all lumped into one 'using'?

In other words, is there a best way to use project classes with 'using'
meaning

is it best to put them all in one folder = no performance hit for doing so
using MyProject.Classes;

or

is it best to put them in different folders to avoid a performance hit by
'using' all of them
using MyProject.Classes.This;
using MyProject.Classes.That;
using MyProject.Classes.Other;

Thank you


Using has no efffect on performance, it is strictly a compile time nicety.
Nov 17 '05 #2
There is no runtime performance penalty based on the number of "using"
directives. The reason to minimize the number of namespaces is not to
improve performance, but to reduce the possibility of name collisions.

For example, if you have a MyFunkyCollection in both
MyCompany.Collections and MyCompany.Collections.Specialized, and you
have a "using" directive for both of those namespaces, the compiler will
not know which MyFunkyCollection you intend unless you qualify it in the
code. So, paradoxically, while "using" directives are intended to
reduce typing of fully qualified names, beyond a certain point they can
actually force you to use more fully qualified names because you have
too broad a list of "using" directives in place.

An example of this in the .NET framework itself is the fact that many UI
controls have the same names for both WinForms and ASP.NET applications
(for example, TextBox). This isn't a practical problem because you
would never actually reference both namespaces in the same application;
that wouldn't make sense. In general, namespaces are organized in such
a way that you would use them in combinations that wouldn't create
ambiguities. However, sometimes namespaces can evolve same-named
classes despite your best intentions, so there's no point in risking an
"ambiguous reference" compiler error by routinely stacking up 30 "using"
directives just in case you ever need anything in those namespaces.

Also, you need to be aware that a given "using" directive is not
inclusive of any levels that might exist beneath it. For example:

using MyProject.Classes

.... would not search MyProject.Classes.This when resolving fully
qualified names. You *must* include them all separately, anyway, if you
want the compiler to find the names within all levels of the namespace
hierarchy.

--Bob
xzzy wrote:
I was wondering why we have to have
using System.Data
using System.Configuration
using etc....

why are they not all lumped into one 'using'?

In other words, is there a best way to use project classes with 'using'
meaning

is it best to put them all in one folder = no performance hit for doing so
using MyProject.Classes;

or

is it best to put them in different folders to avoid a performance hit by
'using' all of them
using MyProject.Classes.This;
using MyProject.Classes.That;
using MyProject.Classes.Other;

Thank you

Nov 17 '05 #3
Daniel and Bob, thank you your answers to my question.

John
Nov 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: byrocat | last post by:
I'm chasing after a documetn that was available on one of the Microsoft websites that was titled somethign like "MS SQL Server Best Practices" and...
136
by: Matt Kruse | last post by:
http://www.JavascriptToolbox.com/bestpractices/ I started writing this up as a guide for some people who were looking for general tips on how to...
13
by: john doe | last post by:
A quick question, about so-called 'best practices', I'm interested in which of A/B of the two examples people would choose, and why. public...
3
by: Jack Frost | last post by:
What is the consensus on putting ASP.NET code inline in the html doc versus using code behind and C#. I find it confusing when pages include code...
1
by: | last post by:
Hi can someone send or point me to Any nice Material on .NET Best Practices -regards
2
by: Amelyan | last post by:
Could anyone recommend a book (or a web site) that defines best practices in ASP.NET application development? E.g. 1) Precede your control id's...
4
by: Luis Esteban Valencia | last post by:
Hello. Can somebody recomend me books of design patterns in c# and best practices too.
0
by: Louis Aslett | last post by:
I hope this is the correct newsgroup for this query (if not please give me a pointer to where is best): I understand the theory of normalisation...
10
by: Ren | last post by:
Hi All, I'm still rather new at vb.net and would like to know the proper way to access private varibables in a class. Do I access the variable...
3
by: John Dalberg | last post by:
I am looking for an ASP.NET application on CodePlex which exemplifies best practices for the following: - Use of interfaces - Seperation of the...
0
by: tammygombez | last post by:
Hey everyone! I've been researching gaming laptops lately, and I must say, they can get pretty expensive. However, I've come across some great...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: CD Tom | last post by:
This happens in runtime 2013 and 2016. When a report is run and then closed a toolbar shows up and the only way to get it to go away is to right...
0
by: CD Tom | last post by:
This only shows up in access runtime. When a user select a report from my report menu when they close the report they get a menu I've called Add-ins...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.