May be bad code or May not be!!!
-
I guest that much. ;-)
"Program testing can be used to show the presence of bugs, but never to show their absence." << please vote!! >>
-
Just saw this code at work:
if( A==B )
{
if( B==C && A!=C)
{
DoABC();
}
else
{
DoWork();
}
}
else if (C==A || C == B)
{
DoWork();
}I have examined, tested over and over, but code never goes or will go to
DoABC();
// ♫ 99 little bugs in the code, // 99 bugs in the code // We fix a bug, compile it again // 101 little bugs in the code ♫
Looks like a test to see if
operator==()
has been implemented correctly for whatever class the variables A, B, and C are instances of.DoABC()
will only be called, ifoperator==()
does not fulfil transitivity. Of course, there is one error: it should be!A==C
instead ofA!=C
, otherwise we cannot be sure there is an error inoperator!=()
. ;) Yeah, right... ;P -
Looks like a test to see if
operator==()
has been implemented correctly for whatever class the variables A, B, and C are instances of.DoABC()
will only be called, ifoperator==()
does not fulfil transitivity. Of course, there is one error: it should be!A==C
instead ofA!=C
, otherwise we cannot be sure there is an error inoperator!=()
. ;) Yeah, right... ;P -
Just saw this code at work:
if( A==B )
{
if( B==C && A!=C)
{
DoABC();
}
else
{
DoWork();
}
}
else if (C==A || C == B)
{
DoWork();
}I have examined, tested over and over, but code never goes or will go to
DoABC();
// ♫ 99 little bugs in the code, // 99 bugs in the code // We fix a bug, compile it again // 101 little bugs in the code ♫
Funny! I think if you want this code work as your meaning, you should override the operator "==", or you convey it into other language such as C#.
There is some white cloud floating on the blue sky. That's the landscape I like.
-
Yes they are string(s) and now i thing to replace this code with just one line
DoWork();
// ♫ 99 little bugs in the code, // 99 bugs in the code // We fix a bug, compile it again // 101 little bugs in the code ♫
Ravi Sant wrote:
replace this code with just one line
DoWork();
But what if
A != B && A != C && B != C
? The original code won't executeDoWork
in that case.
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
Ravi Sant wrote:
replace this code with just one line
DoWork();
But what if
A != B && A != C && B != C
? The original code won't executeDoWork
in that case.
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
Just saw this code at work:
if( A==B )
{
if( B==C && A!=C)
{
DoABC();
}
else
{
DoWork();
}
}
else if (C==A || C == B)
{
DoWork();
}I have examined, tested over and over, but code never goes or will go to
DoABC();
// ♫ 99 little bugs in the code, // 99 bugs in the code // We fix a bug, compile it again // 101 little bugs in the code ♫
The only minute possibility of it being useful perhaps, is if there are multiple threads involved. . .and maybe if it is the case that A is static or something. . . .that if there was a CPU context switch between the lines if( A==B ) and if( B==C && A!=C) ...where A gets changed by another thread therefore the programmer had been trying to be uber careful about running DoABC(). . . . .??
-
If equality is transitive (and I really hope it is), it can indeed never execute DoABC. Given A == B and B == C, it follows from transitivity that A == C, so A != C must be false.
Don't forget, in at least some languages, you're allowed to override operators. So A's == may not be the same as B's. That might be a path to DoABC. In the absence of that, though, what he said. In the presence of that, that's a whole other kind of bad development.
-
Just saw this code at work:
if( A==B )
{
if( B==C && A!=C)
{
DoABC();
}
else
{
DoWork();
}
}
else if (C==A || C == B)
{
DoWork();
}I have examined, tested over and over, but code never goes or will go to
DoABC();
// ♫ 99 little bugs in the code, // 99 bugs in the code // We fix a bug, compile it again // 101 little bugs in the code ♫
-
I guest that much. ;-)
"Program testing can be used to show the presence of bugs, but never to show their absence." << please vote!! >>
R. Erasmus wrote:
I guest that much.
Did you guest anonymously? - Oh, sorry - the bad-English-and-spelling thread was yesterday ... ;)
-
Under normal circumstances equality is transitive; but it also isn't permanent... :)
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
-
The variables A, B, C may be equal at some point in time, they also are variables, hence their value can change. See also here[^]. :)
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.