|
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.
|
|
|
|
|
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.
|
|
|
|
|
I didn't pasted it twice, it was like that in a file.
Ahsan Ullah
Senior Software Engineer
|
|
|
|
|
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.
|
|
|
|
|
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 second abc 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...
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.
|
|
|
|
|
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.
But using 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.
|
|
|
|
|
Hmmmm. You'd think the compiler would catch something like that.
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
"Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham
|
|
|
|
|
|
I guess can't blame the compiler for catching it. I wonder why he (programmer) used it like that.
And i also wonder if he did it twice why not thrice
Ahsan Ullah
Senior Software Engineer
|
|
|
|
|
Try to compile following without first or second using:
using System;
namespace MyCode.Console
{
using System;
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Test");
}
}
}
|
|
|
|
|
bool foo(int n)
{
if (n > 16)
return true;
else if (n <= 16)
return false;
else
return false;
}
i love this one!
|
|
|
|
|
|
this sort of thing can happen if you blindly follow the compiler checking messages
if (n > 16)<br />
return true;<br />
else if (n <= 16)<br />
return false;
would probably report that not all paths return a value
so the developer adds the else to get rid of the error. Granted with ints you should pick it up if you're not in a hurry but with more complex objects it's always possible to end up in this case without thinking.
Russell
|
|
|
|
|
Oh c'mon:
Use return (n > 16); and don't even consider thinking...
Regards
Thomas
|
|
|
|
|
bool foo(int n)<br />
{<br />
if (n > 16)<br />
return true;<br />
else if (n <= 16 && n>4)<br />
return false;<br />
else if (n <= 4)<br />
return true;<br />
}
Coding from scratch, I agree but it's late on deadline day when someone realises that the case of n<=4 no longer applies, these kind of things can happen.
|
|
|
|
|
Very good point - I fully agree. You gave a good example on how things like that can (and all too often will) happen in real word.
But nevertheless the result is kind of 'coding horror' and urgently needs refactoring after deadline day.
Regards
Thomas
|
|
|
|
|
Russell Jones wrote: bool foo(int n)
{
if (n > 16)
return true;
else if (n <= 16 && n>4)
return false;
else if (n <= 4)
return true;
}
But it too would be better though as:
bool foo(int n)
{
return ((n > 16) || (n <= 4));
}
|
|
|
|
|
Indeed..what thought is required to come to that conclusion??
|
|
|
|
|
Ummm....
<br />
if (n > 16)<br />
return true;<br />
else
return false;<br />
|
|
|
|
|
shadayim wrote: i love this one!
Me too: 5 .
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|