473,378 Members | 1,360 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

When To Use Imports And When To Use The Full Namespace Path ?

Hi ,

I have an assembly that hold few class and few imports which are not used in
all of the class's .

so my question is when to use the "Imports XXX"

And when to use this kind of statement

Dim X as New System.XXX ....

And in which way the performance will be better ?
Best Regards ,

Tiraman :-)
Nov 20 '05 #1
19 1818
On Tue, 25 May 2004 15:30:58 +0200, Tiraman wrote:

so my question is when to use the "Imports XXX"

And when to use this kind of statement


The imports statement is just there to save you some typing. I don't
believe it affects performance at all.

I think that you should use the Imports statement to save some time, but
only if it does not make the code ambiguous. Use full or partial
namespaces when it makes the code clearer. Mostly, I think, it is a matter
of personal taste. Others may have alternate opinions.

--
Chris

To send me an E-mail, remove the "[", "]", underscores ,lunchmeat, and
replace certain words in my E-Mail address.
Nov 20 '05 #2
Tiraman,
And in which way the performance will be better ?
Imports is a developer productivity aid, it does not impact runtime
performance at all.

So when to use Imports & when not, depends entirely on you.

Hope this helps
Jay

"Tiraman" <ti*****@netvision.net.il> wrote in message
news:uN**************@TK2MSFTNGP11.phx.gbl... Hi ,

I have an assembly that hold few class and few imports which are not used in all of the class's .

so my question is when to use the "Imports XXX"

And when to use this kind of statement

Dim X as New System.XXX ....

And in which way the performance will be better ?
Best Regards ,

Tiraman :-)

Nov 20 '05 #3
Hi Tiraman,

In some casses it is better not to use the import.

The import imports the namespace in your IDE, that means that if it is a
namespace with a bunch of properties, interfaces whatever your IDE get
totally locked.

My example is MSHTML which make the IDE absolute unusable when an import is
set.

For that it is better to use the Full namespace, (which is also terrible
slow to set for that).

However this are exceptions I assume.

Cor
Nov 20 '05 #4
* "Tiraman" <ti*****@netvision.net.il> scripsit:
I have an assembly that hold few class and few imports which are not used in
all of the class's .

so my question is when to use the "Imports XXX"

And when to use this kind of statement

Dim X as New System.XXX ....


In addition to the other comments: I /always/ import /all/ the
namespaces classes I am using reside in. So it's very easy to see what
namespaces are used by a class by taking a look at the 'Imports'
statements (sorted in alphabetical order). That's my convention...

Just my 2 Euro cents...

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #5
In article <2h************@uni-berlin.de>, Herfried K. Wagner [MVP] wrote:
* "Tiraman" <ti*****@netvision.net.il> scripsit:
I have an assembly that hold few class and few imports which are not used in
all of the class's .

so my question is when to use the "Imports XXX"

And when to use this kind of statement

Dim X as New System.XXX ....


In addition to the other comments: I /always/ import /all/ the
namespaces classes I am using reside in. So it's very easy to see what
namespaces are used by a class by taking a look at the 'Imports'
statements (sorted in alphabetical order). That's my convention...

Just my 2 Euro cents...


That's funny... I do mine by the length... In other words:

Imports System
Imports System.Net
Imports System.Text
Imports System.Threading
Imports System.Net.Sockets
Imports System.Runtime.InteropServices
....

And I import everything as well (though, in my case, since I am almost
always using C#, it's actually using but same diff :)

--
Tom Shelton [MVP]
Nov 20 '05 #6
That shows that you never used Mshtml

Cor
Nov 20 '05 #7
Tom,

* Tom Shelton <to*@YOUKNOWTHEDRILLmtogden.com> scripsit:
so my question is when to use the "Imports XXX"

And when to use this kind of statement

Dim X as New System.XXX ....


In addition to the other comments: I /always/ import /all/ the
namespaces classes I am using reside in. So it's very easy to see what
namespaces are used by a class by taking a look at the 'Imports'
statements (sorted in alphabetical order). That's my convention...

Just my 2 Euro cents...


That's funny... I do mine by the length... In other words:


That's what I did for a long time, but then I sorted them
alphabetically. It's just a matter of preference, but alphabetical
order makes finding imports easier, especially if there are > 10
imports.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #8
"Tiraman" <ti*****@netvision.net.il> wrote in message news:<uN**************@TK2MSFTNGP11.phx.gbl>...
so my question is when to use the "Imports XXX"

And when to use this kind of statement

Dim X as New System.XXX ....

And in which way the performance will be better ?


To me, it depends on how much I'm using a namespace.

Am I just using Math.Round() in one or two places? Then I'll type out
System.Math.Round - no big deal. Am I doing an intense printing job?
Then I'll Import System.Drawing.Printing. (And sometimes I do both,
on odd occasions when I want to be clear to a future developer where
something comes from.)

John Fiala
jcfiala523-at-hotmail.com
http://www.livejournal.com/users/fiala_tech/
Nov 20 '05 #9
Herfried,
I normally do mine in order of importance, where order of importance does
not matter I use alphabetically.

Order of importance matters where you may have the same Name in more then
one Namespace or Class/Module.

For example:
Imports Microsoft.VisualBasic.Interaction
Imports MyUtilities.MyGenerics

I have an intelligent, overloaded and typesafe IIf in MyUtilities.MyGenerics
while the Interaction.IIf only works with objects. I obviously want to be
certain that MyUtilities.MyGenerics is imported first!

Hope this helps
Jay
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:2h************@uni-berlin.de...
* "Tiraman" <ti*****@netvision.net.il> scripsit:
I have an assembly that hold few class and few imports which are not used in all of the class's .

so my question is when to use the "Imports XXX"

And when to use this kind of statement

Dim X as New System.XXX ....


In addition to the other comments: I /always/ import /all/ the
namespaces classes I am using reside in. So it's very easy to see what
namespaces are used by a class by taking a look at the 'Imports'
statements (sorted in alphabetical order). That's my convention...

Just my 2 Euro cents...

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>

Nov 20 '05 #10
* jc********@hotmail.com (John Fiala) scripsit:
And when to use this kind of statement

Dim X as New System.XXX ....

And in which way the performance will be better ?


To me, it depends on how much I'm using a namespace.

Am I just using Math.Round() in one or two places? Then I'll type out
System.Math.Round - no big deal. Am I doing an intense printing job?
Then I'll Import System.Drawing.Printing. (And sometimes I do both,
on odd occasions when I want to be clear to a future developer where
something comes from.)


Yep, but even that won't have any influence on execution time.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #11
* "Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> scripsit:
I normally do mine in order of importance, where order of importance does
not matter I use alphabetically.

Order of importance matters where you may have the same Name in more then
one Namespace or Class/Module.

For example:
Imports Microsoft.VisualBasic.Interaction
Imports MyUtilities.MyGenerics

I have an intelligent, overloaded and typesafe IIf in MyUtilities.MyGenerics
while the Interaction.IIf only works with objects. I obviously want to be
certain that MyUtilities.MyGenerics is imported first!


OK, that's a good idea and sometimes it's necessary.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #12
hi every one ,

1st i would like to 10x you all for your answers .
as far as i understand you all most of you use the imports in order to save
some typing but the main issue is that it doesn't
effect the performance so my question is why Microsoft didn't put them all
in each page as default so it will save us
the typing and the searching for the namespace ?

10x again .
"Tiraman" <ti*****@netvision.net.il> wrote in message
news:uN**************@TK2MSFTNGP11.phx.gbl...
Hi ,

I have an assembly that hold few class and few imports which are not used in all of the class's .

so my question is when to use the "Imports XXX"

And when to use this kind of statement

Dim X as New System.XXX ....

And in which way the performance will be better ?
Best Regards ,

Tiraman :-)

Nov 20 '05 #13
Hi Tiraman,
effect the performance so my question is why Microsoft didn't put them all
in each page as default so it will save us
the typing and the searching for the namespace ?


I thought that my message did give an answer on this question.
Charles Law could have given that answer as well.

Cor
Nov 20 '05 #14
Tiraman,
How is Microsoft going to decide which to include on in a source? Should it
include EVERY namespace in the Framework? For a class that has 20 lines of
code you would have 100+ lines of imports. Plus as Cor stated, this may
cause problems for the IDE. When Whidbey (VS.NET 2005) is released there
will be a significant increase in the number of namespaces in the Framework.

If you are not using regular expressions, should Microsoft import the
System.Text.RegularExpression namespace? What happens when you have defined
a Match class and the System.Text.RegularExpression.Match class starts
shadowing your Match class?

If you are creating a Windows Forms application, should System.Web.UI be
imported? What happens when I actually use a class from the above namespace
in my Windows Forms app?

Microsoft does not import all the namespaces because you as developer need
to decide which namespaces are appropriate to the class/structure that you
are currently working on.

Remember that namespaces are used to organize the types (classes,
structures, delegates) in the framework & your assemblies, if you
automatically imported every thing, then you really would not need
namespaces and you would suddenly be disorganized!

Take for example the Timer class, without Namespaces which of the three
Timers are you referring to? System.Threading.Timer, System.Timers.Timer,
or System.Windows.Forms.Timer?

The namespace part of the above Timer's name is what makes each class
distinct from the other, without needing to do something funky like
"ThreadTimer", "ServerTimer", "FormTimer", which IMHO is more awkward then
using the Namespace, considering that the namespace groups related types in
a central location (System.Windows.Forms has all the Windows Forms stuff).

Hope this helps
Jay

"Tiraman" <ti*****@netvision.net.il> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
hi every one ,

1st i would like to 10x you all for your answers .
as far as i understand you all most of you use the imports in order to save some typing but the main issue is that it doesn't
effect the performance so my question is why Microsoft didn't put them all
in each page as default so it will save us
the typing and the searching for the namespace ?

10x again .
"Tiraman" <ti*****@netvision.net.il> wrote in message
news:uN**************@TK2MSFTNGP11.phx.gbl...
Hi ,

I have an assembly that hold few class and few imports which are not
used in
all of the class's .

so my question is when to use the "Imports XXX"

And when to use this kind of statement

Dim X as New System.XXX ....

And in which way the performance will be better ?
Best Regards ,

Tiraman :-)


Nov 20 '05 #15
* "Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> scripsit:
Remember that namespaces are used to organize the types (classes,
structures, delegates) in the framework & your assemblies, if you
automatically imported every thing, then you really would not need
namespaces and you would suddenly be disorganized!


Namespaces help finding classes. Importing /all/ available namespaces
doesn't make sense, but importing all namespaces used in the class makes
sense. Sometimes it will be, as you say, necessary to qualify a class
to avoid ambiguity, or alternatively set up an alias for the class name
using 'Imports'.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #16
Hi Herfried,

Try once what I said, and set that MSHTML in your import from all your
programs a week, we do not get one message anymore that week when you are
doing that.

And what I did not think about, however thought when I readed the last
message from Jay who said that explicitly, what will happen as well when you
have to much imports from large namespaces.

It makes sense as Jay said when it is possible, as what I did mean with my
message as well.

Cor

Namespaces help finding classes. Importing /all/ available namespaces
doesn't make sense, but importing all namespaces used in the class makes
sense. Sometimes it will be, as you say, necessary to qualify a class
to avoid ambiguity, or alternatively set up an alias for the class name
using 'Imports'.

Nov 20 '05 #17
* "Cor Ligthert" <no**********@planet.nl> scripsit:
Try once what I said, and set that MSHTML in your import from all your
programs a week, we do not get one message anymore that week when you are
doing that.

And what I did not think about, however thought when I readed the last
message from Jay who said that explicitly, what will happen as well when you
have to much imports from large namespaces.


Performance should not be a reason not to follow a certain pattern, but
in some situations there may be performance problems that force me to
not import the namespace.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #18
Herfried,
When I stated "imported every thing" I was referring to all 120+ namespaces
in the framework. ;-)

I agree, I normally import the 4 or 5 specific namespaces that I need in a
single class. I will occasionally import either the class (System.Math for
example) or use an Alias (Outlook for example).

Jay

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:2h************@uni-berlin.de...
* "Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> scripsit:
Remember that namespaces are used to organize the types (classes,
structures, delegates) in the framework & your assemblies, if you
automatically imported every thing, then you really would not need
namespaces and you would suddenly be disorganized!


Namespaces help finding classes. Importing /all/ available namespaces
doesn't make sense, but importing all namespaces used in the class makes
sense. Sometimes it will be, as you say, necessary to qualify a class
to avoid ambiguity, or alternatively set up an alias for the class name
using 'Imports'.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>

Nov 20 '05 #19
i think that i got the idea
so 10x to all of you !

"Tiraman" <ti*****@netvision.net.il> wrote in message
news:#s**************@TK2MSFTNGP11.phx.gbl...
hi every one ,

1st i would like to 10x you all for your answers .
as far as i understand you all most of you use the imports in order to save some typing but the main issue is that it doesn't
effect the performance so my question is why Microsoft didn't put them all
in each page as default so it will save us
the typing and the searching for the namespace ?

10x again .
"Tiraman" <ti*****@netvision.net.il> wrote in message
news:uN**************@TK2MSFTNGP11.phx.gbl...
Hi ,

I have an assembly that hold few class and few imports which are not
used in
all of the class's .

so my question is when to use the "Imports XXX"

And when to use this kind of statement

Dim X as New System.XXX ....

And in which way the performance will be better ?
Best Regards ,

Tiraman :-)


Nov 20 '05 #20

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

Similar topics

1
by: Craig Ringer | last post by:
Hi folks I'm a bit of a newbie here, though I've tried to appropriately research this issue before posting. I've found a lot of questions, a few answers that don't really answer quite what I'm...
4
by: LjP | last post by:
I wonder if using Imports keyword or using full name influences performance of app?
10
by: Not Available | last post by:
On the host server: namespace JCart.Common public class JCartConfiguration : IConfigurationSectionHandler private static String dbConnectionString; public static String ConnectionString { get...
2
by: brin | last post by:
I have the following vb class and am trying to compile it using vbc.exe. I receive errors stating that System.Data and System.Data.SqlClient cannot be imported. I am fairly new to this, any help...
3
by: Joe via DotNetMonster.com | last post by:
Hi, I'm creating a Class file that contains a function that queries the database. I receive alot of connection type errors when I try to compile and I'm not sure what I'm doing wrong. This is...
4
by: Jeff Jarrell | last post by:
I am not really there yet with namespaces. I have a "common.dll" that is referenced from another project. now in the consuming project, source file to i'd like to have a "imports common". ...
1
by: connah | last post by:
Hi All! How can I obtain the full XML path of any given XML Node? For example, if my XML document looks like this: ---BEGIN XML DOC--- <Tag1> <Tag2> <Tag3></Tag3> </Tag2>
0
by: Chris | last post by:
I'm having trouble with the sample below since moving from Atlas to AJAX. I've done a LOT of research with prototypes and delegates, but I cant get this simple, "class-like" example to work. Any...
5
by: kimiraikkonen | last post by:
Hello, I want to ask about "imports" statement. Some projects must be inserted with "imports xxxx" statements before beginning coding. But how do i know when to use or do i have to use "imports"...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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.