|
Well, you made the lazy CPU working...
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.
|
|
|
|
|
|
No worries, one Sleep could save you
codito ergo sum
|
|
|
|
|
I think it already happened to everyone to rewrite existing code or API just because one did not know that the code already existed.
In a different manner, as I was a student, it took me one week to transform serial signals (-12/+12 Volts) into a (0/+5V) signals using all kind of electronic beings (resistance, amplifier, ...) just to find out after that that someone had already thought about the problem and that we could buy RS232 integrated circuits everywhere.
Constantly "Saving the day" should be taken as a sign of organizational dysfunction rather than individual skill - Ryan Roberts[^]
|
|
|
|
|
Yeah, I'd probably cringe if I had to look at some of the "code"(I use the term loosly) that I wrote right out of college.
|
|
|
|
|
This doesn't register with me, I learned threads with Java ... Maybe comment and point out mistakes ?
Je vous salue du Québec !
|
|
|
|
|
|
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.
|
|
|
|
|
I've just modified it to use <pre> tags
---
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
|
|
|
|
|
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.
|
|
|
|
|
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;
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 !
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.
|
|
|
|
|
Why, oh why? Use modulus , pleeaaassee
|
|
|
|
|
Simply because they weren't able to use it...
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.
|
|
|
|
|
mov eax, dword [nTotalMinutes]
xor edx, edx
mov ebx, 60
div ebx
cinvoke printf, <"Time %d:%d",0x10>, eax, edx
I heart assembly.
|
|
|
|
|
sk8er_boy287 wrote: I heart assembly
Expecially when a single instruction perform two operations
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.
|
|
|
|
|
private bool isValid(int testValue, int minValue, int maxValue)
{
return ( (minValue <= testValue) && (testValue <= maxValue) );
}
Fixed
|
|
|
|
|
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?
|
|
|
|
|
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..."
|
|
|
|
|
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.
|
|
|
|
|
At one time or another, we've all coded a horror. I know I have
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
Thankfully, this won't even compile using the VS2005 C# compiler.
/ravi
|
|
|
|
|
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
|
|
|
|