using directive vs explicit qualification. Which performs better?

  • Thread starter Thread starter Jimmy
  • Start date Start date
J

Jimmy

Hi,
The other day, my boss corrected me to use "explicit qualification"
instead of using "using directive".

she asked me to use :

"System.Data.DataSet ds = new System.Data.DataSet();"

instead of :

"using System.Data;
DataSet ds = new DataSet();"

She was insisting that by using "explicit qualification", the machine
would recognize the code faster than those used "using directive".

Is that true? I am looking for some article to clarify this. If anyone
the answer which performs better or both perform exactly the same with
solid evidence and proof, let me know.

Thanks
 
Once the code is compiled, there is no difference at all.

As to which compiles quicker... I suspect "neither by any margin you'd
ever notice"...

So in short, your boss is wrong.

There are some cases when explicit usage is handy to disambiguate
between two classes named the same in different namespaces (although
aliasing is also an option here).

Marc
 
The other day, my boss corrected me to use "explicit qualification"
instead of using "using directive".

Time to get a new boss, or at least time to make it clear that old
wives' tales shouldn't influence development.
she asked me to use :

"System.Data.DataSet ds = new System.Data.DataSet();"

instead of :

"using System.Data;
DataSet ds = new DataSet();"

She was insisting that by using "explicit qualification", the machine
would recognize the code faster than those used "using directive".

Is that true? I am looking for some article to clarify this. If anyone
the answer which performs better or both perform exactly the same with
solid evidence and proof, let me know.

No, it's certainly not true. The compiled code will be identical both
ways. Use ildasm to show this, or just compile the code both ways and
look at the differences with a hex diff program. (There will be
differences whenever you rebuild due to autogenerated GUIDs, hashes,
timestamps etc - but the region for the difference will be the same
for a recompile with some trivial change (e.g. whitespace) as for
using a using directive vs "explicit qualification".

I'd be interested to see any "proof" she provides for her suggestion.

Jon
 
It is not true.

The IL code that is generated is exactly the same anyway.

The "using" concept is not applicable at IL level, everything is written
explicitly with fully qualified names.

It could be seen only as a convience keyword.

It is a recommended practice to use using statements when a member from that
namespace is used more than once, or possibly will.

There are some contexts where i like not to use using, these are interfaces
and enums, but that is just my practice(since they are rarely meant to be
extended, using should not be needed for future convience). It is like
underscoring that this implementation is final.

But otherwise, using fully qualified names will fill the editor up with a
lot of unnecessary code and repeating patterns.
 
It is not true.

The IL code that is generated is exactly the same anyway.

The "using" concept is not applicable at IL level, everything is written
explicitly with fully qualified names.

It could be seen only as a convience keyword.

It is a recommended practice to use using statements when a member from that
namespace is used more than once, or possibly will.

There are some contexts where i like not to use using, these are interfaces
and enums, but that is just my practice(since they are rarely meant to be
extended, using should not be needed for future convience). It is like
underscoring that this implementation is final.

But otherwise, using fully qualified names will fill the editor up with a
lot of unnecessary code and repeating patterns.

Thanks a lot guys.

Although I've been coding for past 8 years and am good at it, I don't
have thorough knowledge from ground up. I usually don't dwell on
something I was corrected, but this one just seemed to be
cumbersome(and I am too lazy to write more code).

I will try that ildasm thing.

Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top