Home All Groups Group Topic Archive Search About

Using using verses specifying the namespace completely.

Author
10 Mar 2006 7:08 PM
UJ
What's the general feeling on using the using keyword versus spelling the
type out completely.

For instance, do most people put a using in so they can just say
MyNewType    or do people not use a using and they specify the
namespace/type like       MyNameSpace.MyNewType

Just curious. I'm leaning towards not using the using and specifying things
because then I know for a fact it's my datatype not a system datatype.

TIA - Jeff.

Author
10 Mar 2006 7:17 PM
dkode
Whatever your decision, keep it the same in all of your code. It will
make it easier for other people to read it if you keep everything the
same.

I guess it's a matter of personal preference. I personally put a using
statement in so that i dont have to continually type out the namespace,
unless of course I have two classes that are named the same, then I
type out the full namespace.

Like I said, just keep it uniform, it will make everything alot easier,
this also applies to private member variables, property accessors,
class names etc. as far as naming conventions go. There is an article
on MSDN (link below) that deals with the naming guidlines (camel
notation, hungarian etc) and other guidelines that you should use.

heres the link:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpgenref/html/cpconnamingguidelines.asp
Are all your drivers up to date? click for free checkup

Author
10 Mar 2006 7:25 PM
Jon Skeet [C# MVP]
UJ <f***@nowhere.com> wrote:
> What's the general feeling on using the using keyword versus spelling the
> type out completely.
>
> For instance, do most people put a using in so they can just say
> MyNewType    or do people not use a using and they specify the
> namespace/type like       MyNameSpace.MyNewType
>
> Just curious. I'm leaning towards not using the using and specifying things
> because then I know for a fact it's my datatype not a system datatype.

You'll find that your code is much more long-winded. Of course, you can
hover over a variable to find out its full type (IIRC) if you really
need to - but most of the time you shouldn't need to. If you avoid
giving your types the same name as common system ones, it shouldn't be
a problem.

I've worked with code which (to me) didn't have enough "using"
statements. It gets very annoying very quickly. Consider:

System.Text.RegularExpressions.Regex regex = new
System.Text.RegularExpressions.Regex (".*");

compared with:

Regex regex = new Regex(".*");

Which of them makes the most important bits of the code (which for me
are the type name, the fact that you're calling a constructor, and the
pattern) the clearest? How important is the namespace in that, really?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet   Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too

Bookmark and Share