May be bad code or May not be!!!
-
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 ♫
-
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 ♫
Woaw that code definitely sucks! And I'm not sure if you are being serious about this so I will put this explanation anyway... But it's testing if A equals B and afterwards if B equals C (and that means both A and B equals C)... And then it only calls DoABC if A don't equals C...
-
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 ♫
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.
-
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 ♫
In any "sane" scenario its pretty obvious that if A==B and B==C then A should equal C therefore DoABC() will never be called. Still with no more information, it is plausible (even if hideous) to think that DoABC could be called. It just needs some dubious implicit cast operators to do the trick.
-
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 assume the data types for A, B and C are something basic? With custom operator overloads you could get to DoABC() using the above logic if you really wanted to. But I think you would need to have different data types
I may or may not be responsible for my own actions
-
I assume the data types for A, B and C are something basic? With custom operator overloads you could get to DoABC() using the above logic if you really wanted to. But I think you would need to have different data types
I may or may not be responsible for my own actions
-
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.
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.
-
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 ♫
You didn't tell us what types A, B, C are. They could be some type with the == operator overloaded by something counter-intuitive. They could also be just stupid integers, stored globally, marked volatile, and changing occasionally... So, yes it looks weird, it probably is a mistake, and OTOH it could function as intended and just be a case of bad, hardly readable, code. :)
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.
-
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 ♫
My Snark Detector is going off.
-
You didn't tell us what types A, B, C are. They could be some type with the == operator overloaded by something counter-intuitive. They could also be just stupid integers, stored globally, marked volatile, and changing occasionally... So, yes it looks weird, it probably is a mistake, and OTOH it could function as intended and just be a case of bad, hardly readable, code. :)
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.
-
I assume the data types for A, B and C are something basic? With custom operator overloads you could get to DoABC() using the above logic if you really wanted to. But I think you would need to have different data types
I may or may not be responsible for my own actions
-
they are string(s) :)
// ♫ 99 little bugs in the code, // 99 bugs in the code // We fix a bug, compile it again // 101 little bugs in the code ♫
-
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 ♫
No matter how hard I try to find the good in this piece of code, I just can't, I'm sorry. 1st bug: meaningless variable names 2nd bug: No '()' to indicate and clarify precedence 3rd bug: Dead code
"Program testing can be used to show the presence of bugs, but never to show their absence." << please vote!! >>
-
No matter how hard I try to find the good in this piece of code, I just can't, I'm sorry. 1st bug: meaningless variable names 2nd bug: No '()' to indicate and clarify precedence 3rd bug: Dead code
"Program testing can be used to show the presence of bugs, but never to show their absence." << please vote!! >>
-
yes, 1st is not bug, I did it purposely to hide actual busines variables. 2& 3 surely bad.
// ♫ 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!! >>
-
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.