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

  • Thread starter Thread starter Geri Reshef
  • Start date Start date
G

Geri Reshef

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?
 
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
 
Geri said:
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.
 
MSDN !! It's almost perfect for such situations. :-)
Anything specific though?

- Sahil Malik
http://dotnetjunkies.com/weblog/sahilmalik


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?
 
J. Jones said:
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?
 
J. Jones said:
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.
 
Paul said:
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.
 
Jon said:
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.
 
J. Jones said:
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.
 
Back
Top