I wonder!!!!
-
AhsanS wrote:
I didn't pasted it twice, it was like that in a file.
Then indeed it's complete nonsense. Does it compile?
_Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
Programmer - an organism that turns coffee into software._
-
Thomas Weller wrote:
- It forces the developer to be explicit about what he's doing - always a good thing. - Types with identical names can occur in more than one namespace. With using you can distinguish them properly. (Take for example System.Windows.Forms.Timer vs. System.Threading.Timer...).
I think you have that backward.
I'm afraid I don't get what you mean... :~ Regards Thomas
_Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
Programmer - an organism that turns coffee into software._
-
AhsanS wrote:
I didn't pasted it twice, it was like that in a file.
Then indeed it's complete nonsense. Does it compile?
_Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
Programmer - an organism that turns coffee into software._
-
Yes it compiles and where the reference is used it is used as using abc.abc it is working perfectly fine and perhaps for these sorts of issue, i am looking into each file again.
Ahsan Ullah Senior Software Engineer
AhsanS wrote:
where the reference is used it is used as using abc.abc
So the author of this piece of code accidentally created a nested namespace... This is syntactically correct and being allowed to do so makes perfect sense - generally. Of course it makes no sense at all to do it that way - I bet this is a CPD (CPD = copy paste desaster :) ). Regards Thomas
_Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
Programmer - an organism that turns coffee into software._
-
I'm afraid I don't get what you mean... :~ Regards Thomas
_Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
Programmer - an organism that turns coffee into software._
Using fully-specified names do what you say; not the
using
directive. -
Using fully-specified names do what you say; not the
using
directive.PIEBALDconsult wrote:
Using fully-specified names do what you say; not the using directive.
There is absolutely no difference (in terms of syntactical functionality) between the two alternatives. The first is totally equivalent to the second. :^) The only difference is that with fully qualified type names you will end up with horrible long lines of code that say nothing more than if the programmer had used a using statement. - You will produce code that tends to become unreadable and your keyboard will soon give up... Regards Thomas
_Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
Programmer - an organism that turns coffee into software._
-
AhsanS wrote:
where the reference is used it is used as using abc.abc
So the author of this piece of code accidentally created a nested namespace... This is syntactically correct and being allowed to do so makes perfect sense - generally. Of course it makes no sense at all to do it that way - I bet this is a CPD (CPD = copy paste desaster :) ). Regards Thomas
_Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
Programmer - an organism that turns coffee into software._
-
it might be CPD, but he must have known the issue when using "using abc.abc"????
Ahsan Ullah Senior Software Engineer
AhsanS wrote:
he must have known the issue
Maybe, maybe not. There are some tools/functionalities out there that generate those
using
statements automatically for you (e.g. VS 2008 and Resharper can do that). And pressing Ctrl+Enter when Intellisense offers you something slightly strange but working (like the secondabc
after the first) is also simpler than thinking about the code. So chances are he was just lazy. Just taking something that reliably works without really understanding why... :suss: Regards Thomas_Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
Programmer - an organism that turns coffee into software._
-
I was just going through block of code for refactoring and found this. I wonder why is this even allowed in .net framework? What is benefit of it after all?
using System;
using System.Collections.Generic;
using System.Text;
using System.Timers;namespace abc{
using System;
using System.Collections.Generic;
using System.Text;
using System.Timers;namespace abc{
Ahsan Ullah Senior Software Engineer
-
I was just going through block of code for refactoring and found this. I wonder why is this even allowed in .net framework? What is benefit of it after all?
using System;
using System.Collections.Generic;
using System.Text;
using System.Timers;namespace abc{
using System;
using System.Collections.Generic;
using System.Text;
using System.Timers;namespace abc{
Ahsan Ullah Senior Software Engineer
Try to compile following without first or second using:
using System; // 1
namespace MyCode.Console
{
using System; // 2class Program { static void Main(string\[\] args) { Console.WriteLine("Test"); } }
}
-
AhsanS wrote:
namespace abc{
Is this really twice in the source or is it just a copy/paste mistake? If so, this code should not compile. If not:
using
statements can occur in one of two places: - Abovenamespace
declaration - Insidenamespace
declaration, but outside any other element This combined with the fact that duplicating ausing
directive is only treated as a warning not as an error, your code will compile - even if it's quite horrible indeed.AhsanS wrote:
What is benefit of it after all?
- It forces the developer to be explicit about what he's doing - always a good thing. - Types with identical names can occur in more than one namespace. With
using
you can distinguish them properly. (Take for exampleSystem.Windows.Forms.Timer
vs.System.Threading.Timer
...). Regards Thomas_Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
Programmer - an organism that turns coffee into software._
modified on Thursday, November 6, 2008 12:30 PM
Actually this doesn't force the developer to do anythin, on the contrary. It allows to use simple class names instead of full class names. If you hvae a name that can refer to more thsn 1 class, you get a compiler error and forced to use the full name, regardless of
using
s. Butusing
s that are not use at the beginning of the file but at the beginning of a namespace sounds like more like an accident than anythign else.