469,935 Members | 1,462 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,935 developers. It's quick & easy.

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 1330
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

10 posts views Thread by eyh5 | last post: by
3 posts views Thread by Edward Diener | last post: by
65 posts views Thread by Spiros Bousbouras | last post: by
reply views Thread by Joe Strout | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.