|
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]
|
|
|
|
|
I've processed that code with WinZip.
The result is:
bool foo(int n) { return (n > 16); }
modified on Tuesday, November 4, 2008 4:34 PM
|
|
|
|
|
Vincenzo Rossi wrote: I've processed that code with WinZip.
I used my brain and got:
n > 16
xacc.ide - now with TabsToSpaces support IronScheme - 1.0 beta 1 - out now! ((lambda (x) `((lambda (x) ,x) ',x)) '`((lambda (x) ,x) ',x))
|
|
|
|
|
I could surrender, but often human beings are stupid and proud.
So I must reply...
Hmmm, ok..
1. this expression cannot be used as callback funcion
2. If you use that expression in many place of your code, instead of using a central function, you have to change the literal 16 in all places. Use a costant at least.
3. Why not waste some stack space? ahah
Greetings
Vin
|
|
|
|
|
That is called "Defensive Programming"
cheers,
Chris Maunder
CodeProject.com : C++ MVP
|
|
|
|
|
Chris Maunder wrote: That is called "Defensive Programming" Roll eyes
Is that because many, many, many military developers use such paradigms?
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]
|
|
|
|
|
Because the developer says, "I was told to do it that way."
|
|
|
|
|
Indeed.
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]
|
|
|
|
|
PIEBALDconsult wrote: Because the developer says, "I was told to do it that way."
If this is defensive programming, there must also be offensive programming and I'd kill them all - programming - because there are a lot of people out there (they call themselves also programmers, so be careful.. ) who give a damn on what someone else is saying, even if it might be their boss. They stick to their bad coding habits regardless of what's happening around them...
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.
|
|
|
|
|