Brings back memories [modified]
-
After reading a few posts on this forum, it makes me remember some horrible code I have written before. (While I was a VB5 programmer) It also reminds me of some horrible code I've seen some other people write, like the following:
private bool isValid(int testValue, int minValue, int maxValue)
{
for (int counter = minValue; counter <= maxValue; counter++)
{
if (testValue == counter)
{
return true;
}
else
{
if (counter == maxValue)
{
return false;
}
}
}
}To make matters worse, they then called this method a few hundred times with min and max Values of 0 and about 500.
--- The sum of the intelligence of the world is constant. The total number of people is always increasing.
-
After reading a few posts on this forum, it makes me remember some horrible code I have written before. (While I was a VB5 programmer) It also reminds me of some horrible code I've seen some other people write, like the following:
private bool isValid(int testValue, int minValue, int maxValue)
{
for (int counter = minValue; counter <= maxValue; counter++)
{
if (testValue == counter)
{
return true;
}
else
{
if (counter == maxValue)
{
return false;
}
}
}
}To make matters worse, they then called this method a few hundred times with min and max Values of 0 and about 500.
--- The sum of the intelligence of the world is constant. The total number of people is always increasing.
Nice, that's a brilliant little horror. p.s. use <pre> tags around your code instead of <code> tags. <pre> tags will preserve the whitespace.
Tech, life, family, faith: Give me a visit. I'm currently blogging about: Master's Decree: It's By My Spirit (audio) The apostle Paul, modernly speaking: Epistles of Paul Judah Himango
-
After reading a few posts on this forum, it makes me remember some horrible code I have written before. (While I was a VB5 programmer) It also reminds me of some horrible code I've seen some other people write, like the following:
private bool isValid(int testValue, int minValue, int maxValue)
{
for (int counter = minValue; counter <= maxValue; counter++)
{
if (testValue == counter)
{
return true;
}
else
{
if (counter == maxValue)
{
return false;
}
}
}
}To make matters worse, they then called this method a few hundred times with min and max Values of 0 and about 500.
--- The sum of the intelligence of the world is constant. The total number of people is always increasing.
hmmm awesome:((
Regards, Sylvester G sylvester_g_m@yahoo.com
-
After reading a few posts on this forum, it makes me remember some horrible code I have written before. (While I was a VB5 programmer) It also reminds me of some horrible code I've seen some other people write, like the following:
private bool isValid(int testValue, int minValue, int maxValue)
{
for (int counter = minValue; counter <= maxValue; counter++)
{
if (testValue == counter)
{
return true;
}
else
{
if (counter == maxValue)
{
return false;
}
}
}
}To make matters worse, they then called this method a few hundred times with min and max Values of 0 and about 500.
--- The sum of the intelligence of the world is constant. The total number of people is always increasing.
Hey, don't knock VB5... Back in the day, it was pretty amazing if you were too lazy/rushed to learn the MFC. As for the code... Wow... Nice one.
-
After reading a few posts on this forum, it makes me remember some horrible code I have written before. (While I was a VB5 programmer) It also reminds me of some horrible code I've seen some other people write, like the following:
private bool isValid(int testValue, int minValue, int maxValue)
{
for (int counter = minValue; counter <= maxValue; counter++)
{
if (testValue == counter)
{
return true;
}
else
{
if (counter == maxValue)
{
return false;
}
}
}
}To make matters worse, they then called this method a few hundred times with min and max Values of 0 and about 500.
--- The sum of the intelligence of the world is constant. The total number of people is always increasing.
Oh, man, I never thought of doing that.
-
Nice, that's a brilliant little horror. p.s. use <pre> tags around your code instead of <code> tags. <pre> tags will preserve the whitespace.
Tech, life, family, faith: Give me a visit. I'm currently blogging about: Master's Decree: It's By My Spirit (audio) The apostle Paul, modernly speaking: Epistles of Paul Judah Himango
-
Oh, man, I never thought of doing that.
PIEBALDconsult wrote:
Oh, man, I never thought of doing that.
I saw the following formatting masterpiece:
int nTotalMinutes; // Total time expressed in minutes
int nHours=0;
int nMinutes=0;
while (nTotalMinutes >= 60)
{
nTotalMinutes -= 60;
nHours++;
}
printf("Time %d:%d\n", nHours, nMinutes);The above snippet only illustrates the concept because, if I remember well, the starting point were
nTotalSeconds
! :-DIf 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.
-
PIEBALDconsult wrote:
Oh, man, I never thought of doing that.
I saw the following formatting masterpiece:
int nTotalMinutes; // Total time expressed in minutes
int nHours=0;
int nMinutes=0;
while (nTotalMinutes >= 60)
{
nTotalMinutes -= 60;
nHours++;
}
printf("Time %d:%d\n", nHours, nMinutes);The above snippet only illustrates the concept because, if I remember well, the starting point were
nTotalSeconds
! :-DIf 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.
Why, oh why? Use
modulus
, pleeaaassee :doh: -
After reading a few posts on this forum, it makes me remember some horrible code I have written before. (While I was a VB5 programmer) It also reminds me of some horrible code I've seen some other people write, like the following:
private bool isValid(int testValue, int minValue, int maxValue)
{
for (int counter = minValue; counter <= maxValue; counter++)
{
if (testValue == counter)
{
return true;
}
else
{
if (counter == maxValue)
{
return false;
}
}
}
}To make matters worse, they then called this method a few hundred times with min and max Values of 0 and about 500.
--- The sum of the intelligence of the world is constant. The total number of people is always increasing.
private bool isValid(int testValue, int minValue, int maxValue)
{
return ( (minValue <= testValue) && (testValue <= maxValue) );
}Fixed :laugh:
-
After reading a few posts on this forum, it makes me remember some horrible code I have written before. (While I was a VB5 programmer) It also reminds me of some horrible code I've seen some other people write, like the following:
private bool isValid(int testValue, int minValue, int maxValue)
{
for (int counter = minValue; counter <= maxValue; counter++)
{
if (testValue == counter)
{
return true;
}
else
{
if (counter == maxValue)
{
return false;
}
}
}
}To make matters worse, they then called this method a few hundred times with min and max Values of 0 and about 500.
--- The sum of the intelligence of the world is constant. The total number of people is always increasing.
At one time or another, we've all coded a horror. I know I have:-D
Deja View - the feeling that you've seen this post before.
-
Why, oh why? Use
modulus
, pleeaaassee :doh: -
private bool isValid(int testValue, int minValue, int maxValue)
{
return ( (minValue <= testValue) && (testValue <= maxValue) );
}Fixed :laugh:
In case you did not notice, the original code has a "bug". If maxValue is less than minValue, then the function may not return anything. In any case, your code is not equivalent to the original code because: isValid(1, 1, 0) returns true with the original code. isValid(1, 1, 0) returns false with your code. Releasing code without testing is dangerous, isn't it? :-D
-
After reading a few posts on this forum, it makes me remember some horrible code I have written before. (While I was a VB5 programmer) It also reminds me of some horrible code I've seen some other people write, like the following:
private bool isValid(int testValue, int minValue, int maxValue)
{
for (int counter = minValue; counter <= maxValue; counter++)
{
if (testValue == counter)
{
return true;
}
else
{
if (counter == maxValue)
{
return false;
}
}
}
}To make matters worse, they then called this method a few hundred times with min and max Values of 0 and about 500.
--- The sum of the intelligence of the world is constant. The total number of people is always increasing.
-
In case you did not notice, the original code has a "bug". If maxValue is less than minValue, then the function may not return anything. In any case, your code is not equivalent to the original code because: isValid(1, 1, 0) returns true with the original code. isValid(1, 1, 0) returns false with your code. Releasing code without testing is dangerous, isn't it? :-D
Xiangyang Liu wrote:
isValid(1, 1, 0) returns true with the original code.
No, the loop wouldn't be entered, so it would return... ummm... oh yeah, that's why it won't compile; "Not all code paths..."
-
After reading a few posts on this forum, it makes me remember some horrible code I have written before. (While I was a VB5 programmer) It also reminds me of some horrible code I've seen some other people write, like the following:
private bool isValid(int testValue, int minValue, int maxValue)
{
for (int counter = minValue; counter <= maxValue; counter++)
{
if (testValue == counter)
{
return true;
}
else
{
if (counter == maxValue)
{
return false;
}
}
}
}To make matters worse, they then called this method a few hundred times with min and max Values of 0 and about 500.
--- The sum of the intelligence of the world is constant. The total number of people is always increasing.
Is that VB5 code? I was forced to write in VB6 once and the code you presented would not have compiled. I understand why this is a coding horror – who ever wrote it needs to find a new line of work. P.S. I am still having trouble believing what I am seeing.
INTP "Program testing can be used to show the presence of bugs, but never to show their absence."Edsger Dijkstra
-
In case you did not notice, the original code has a "bug". If maxValue is less than minValue, then the function may not return anything. In any case, your code is not equivalent to the original code because: isValid(1, 1, 0) returns true with the original code. isValid(1, 1, 0) returns false with your code. Releasing code without testing is dangerous, isn't it? :-D
the original code has a "bug". If maxValue is less than minValue
That may be true if the intent is to determine whether or not the test value "is between" the other two values; which is likely, but may not be the case. As to improving the efficiency of the routine... I've had bosses who would say, "It's always been that way, don't change it." And colleagues who would say, "It ain't broke, don't fix it." In one memorable case I bloody well did fix it, and the result was that the program took ten minutes to run rather than forty... and I was out of a job. Yes, I'd do it again.
-
PIEBALDconsult wrote:
Oh, man, I never thought of doing that.
I saw the following formatting masterpiece:
int nTotalMinutes; // Total time expressed in minutes
int nHours=0;
int nMinutes=0;
while (nTotalMinutes >= 60)
{
nTotalMinutes -= 60;
nHours++;
}
printf("Time %d:%d\n", nHours, nMinutes);The above snippet only illustrates the concept because, if I remember well, the starting point were
nTotalSeconds
! :-DIf 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.
-
mov eax, dword [nTotalMinutes]
xor edx, edx
mov ebx, 60
div ebx
cinvoke printf, <"Time %d:%d",0x10>, eax, edxI heart assembly.:-D
sk8er_boy287 wrote:
I heart assembly
Expecially when a single instruction perform two operations:-D Not available to us, poor C programmers:(( :)
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.
-
After reading a few posts on this forum, it makes me remember some horrible code I have written before. (While I was a VB5 programmer) It also reminds me of some horrible code I've seen some other people write, like the following:
private bool isValid(int testValue, int minValue, int maxValue)
{
for (int counter = minValue; counter <= maxValue; counter++)
{
if (testValue == counter)
{
return true;
}
else
{
if (counter == maxValue)
{
return false;
}
}
}
}To make matters worse, they then called this method a few hundred times with min and max Values of 0 and about 500.
--- The sum of the intelligence of the world is constant. The total number of people is always increasing.
took a long time to work out what that code actually does. I kept looking at it and thinking "No surely that's not it". Now i realise that that is the true horror of this creation. On top of that i can only guess the result of having testvalue > maxvalue but i guess as a private method it can expect sanitised input. wow, Russ
-
After reading a few posts on this forum, it makes me remember some horrible code I have written before. (While I was a VB5 programmer) It also reminds me of some horrible code I've seen some other people write, like the following:
private bool isValid(int testValue, int minValue, int maxValue)
{
for (int counter = minValue; counter <= maxValue; counter++)
{
if (testValue == counter)
{
return true;
}
else
{
if (counter == maxValue)
{
return false;
}
}
}
}To make matters worse, they then called this method a few hundred times with min and max Values of 0 and about 500.
--- The sum of the intelligence of the world is constant. The total number of people is always increasing.