473,322 Members | 1,911 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,322 software developers and data experts.

How to find the appropriate "using" for a variable declararion?

Many times I find code examples in the internet which don't have the "using" statements needed to run them, and without it the compilation fails.
Is there a way to find the correct "using" statement given the variable declaration?
Nov 16 '05 #1
8 1454
Many times I find code examples in the internet which don't have the "using" statements needed to run them, and without it the compilation fails.
Is there a way to find the correct "using" statement given the variable declaration?


If it uses types from the BCL, you can simply type in the class name
in the documentation to figure out which namespace it's in.

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 16 '05 #2
Geri Reshef wrote:
Many times I find code examples in the internet which don't have the
"using" statements needed to run them, and without it the compilation fails.
Is there a way to find the correct "using" statement given the variable
declaration?


This is one of the main reasons that the using construct has no place in modern
languages. Unfortunately for us, it is there.

In the meantime, you have to resort to looking up the item in the help system,
and from there, determine the appropriate reference.
Nov 16 '05 #3
MSDN !! It's almost perfect for such situations. :-)
Anything specific though?

- Sahil Malik
http://dotnetjunkies.com/weblog/sahilmalik
"Geri Reshef" <Ge********@Yahoo.com> wrote in message
news:eE**************@TK2MSFTNGP14.phx.gbl...
Many times I find code examples in the internet which don't have the "using"
statements needed to run them, and without it the compilation fails.
Is there a way to find the correct "using" statement given the variable
declaration?
Nov 16 '05 #4
J. Jones <jj@networld.com> wrote:
Geri Reshef wrote:
Many times I find code examples in the internet which don't have the
"using" statements needed to run them, and without it the compilation fails.
Is there a way to find the correct "using" statement given the variable
declaration?


This is one of the main reasons that the using construct has no place
in modern languages. Unfortunately for us, it is there.


It's likely to be in almost any language which involves namespaces
though. Out of interest, what would you propose instead? No namespaces,
or all namespaces being used by default, with full names only being
used for conflict resolution?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #5
"J. Jones" <jj@networld.com> wrote:
the using construct has no place in modern
languages.


I'd say it certainly beats the messiness of traditional VB, where
dozens (hundreds?) of unrelated functions are lumped together without
any kind of organisation. PHP has similar issues: there aren't any
namespaces, so (in the hope of avoiding naming conflicts) functions
are given horrendously long prefixed names like
'cachingrecursiveiterator-haschildren'.

What would you suggest instead for a modern language, if it is to be
extensible with new libraries?

P.
Nov 16 '05 #6
Paul E Collins wrote:
"J. Jones" <jj@networld.com> wrote:

the using construct has no place in modern
languages.

I'd say it certainly beats the messiness of traditional VB, where
dozens (hundreds?) of unrelated functions are lumped together without
any kind of organisation. PHP has similar issues: there aren't any
namespaces, so (in the hope of avoiding naming conflicts) functions
are given horrendously long prefixed names like
'cachingrecursiveiterator-haschildren'.

What would you suggest instead for a modern language, if it is to be
extensible with new libraries?

P.


Don't confuse using w/ namespaces -- namespaces are an important part of any
language, using isn't.

See my other reply in this thread for solutions.
Nov 16 '05 #7
Jon Skeet [C# MVP] wrote:
J. Jones <jj@networld.com> wrote:
Geri Reshef wrote:
Many times I find code examples in the internet which don't have the
"using" statements needed to run them, and without it the compilation fails.
Is there a way to find the correct "using" statement given the variable
declaration?


This is one of the main reasons that the using construct has no place
in modern languages. Unfortunately for us, it is there.

It's likely to be in almost any language which involves namespaces
though. Out of interest, what would you propose instead? No namespaces,
or all namespaces being used by default, with full names only being
used for conflict resolution?


Yes, very likely to have using, although far from necessary.

All names should be fully qualified. The _editor_ should provide for
(automatic) name collapse while viewing, as well as provide intellisense and/or
auto-lookup for names as you type. For example, if you type "Form", the editor
automatically looks up in the referenced assemblies "Form" and prepends the
applicable namespace (System.Windows.Forms) and then collapses it down.

No matter how you look at it, using is a band-aid for lazy programmers and/or
poor IDEs.
Nov 16 '05 #8
J. Jones <jj@networld.com> wrote:
Yes, very likely to have using, although far from necessary.

All names should be fully qualified. The _editor_ should provide for
(automatic) name collapse while viewing, as well as provide intellisense and/or
auto-lookup for names as you type. For example, if you type "Form", the editor
automatically looks up in the referenced assemblies "Form" and prepends the
applicable namespace (System.Windows.Forms) and then collapses it down.

No matter how you look at it, using is a band-aid for lazy
programmers and/or poor IDEs.


Not the way I look at it :)

I like code to be readable (and writable) in just a plain text editor,
if necessary.

There's nothing to stop the IDE being smarter at managing the using
statements, however. Eclipse's JDT tooling would do the equivalent of
looking up Form in the appropriate assemblies, and adding a using
statement for you if there wasn't one already. (It also provides the
ability to remove using statements that aren't used any more, and
sort/organise those statements.) Very handy - but the code itself is
still the same.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #9

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

Similar topics

13
by: Jalal | last post by:
I am trying to use numeric_limits<double>::min() in an MFC application in Microsoft Visual C++.NET 2003. I am having some difficulties here. The following are the parts of a simple program I wrote...
2
by: K Williams | last post by:
I recently discovered that you can do the following: if currentdb.openrecordset ("select statement.....").eof = true then for cases when you just want to see if any records exist. This...
10
by: eyh5 | last post by:
Hi, My C code (running on Soalris Unix) has some "segmentation fault" that I wish to use purify to do it. I poked around the web, and found some information about adding some lines in a Makefile...
3
by: Edward Diener | last post by:
In Managed C++ one could use __super to invoke a base class function. Has this been changed to "super" or is it still "__super" ? Looking through the MSDN help I could not find a hit for just...
21
by: comp.lang.tcl | last post by:
set php {<? print_r("Hello World"); ?>} puts $php; # PRINTS OUT <? print_r("Hello World"); ?> puts When I try this within TCL I get the following error:
25
by: samjnaa | last post by:
Please check for sanity and approve for posting at python-dev. In Visual Basic there is the keyword "with" which allows an object- name to be declared as governing the following statements. For...
9
by: Chad | last post by:
This might be a bit vague and poorly worded..... In my program, I handle function failures using fprintf() and exit() like: fprintf(stderr, "malloc failed"); exit(EXIT_FAILURE); There...
65
by: Spiros Bousbouras | last post by:
Has anyone found that declaring variables register affected speed of execution ? If yes on what hardware and around which year ?
0
by: Joe Strout | last post by:
Hi Luis, A static variable IS encapsulation. Encapsulation happens at many levels: module, class, instance, and (in languages that support it) method. A static local variable is simply the...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
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...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
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...

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.