|
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
|
|
|
|
|
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
|
|
|
|
|
OMFG ! Did his manager review ANY of his work ?
Je vous salue du Québec !
|
|
|
|
|
Being new to WPF, I've been using the excellent Lutz Reflector[^] to browse through some APIs in .NET 3.0 (in particular, some WPF APIs) and found this goofy gem. Not so much a "horror" as it is a "what the heck?" Thought it worthy of posting here:
Obviously.png[^]
I'm sure there's some deep technical reason for this, probably related to virtual methods vs. pure abstract methods. Just thought the name was kind of funny, plus it ends up calling IsEmpty.
|
|
|
|
|
Have you ever emptied out a pail of water and stood the pail back up only to come back to the pail in 5 minutes and there is still water in it. It's empty, but it's not obviously empty.
Chris Meech
I am Canadian. [heard in a local bar]
|
|
|
|
|
I like the one below it. MayHaveCurves It sounds salacious.
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
MayHaveCurves and ObviouslyEmpty .
Class Blonde ?
*ducks and runs*
"Throughout human history, we have been dependent on machines to survive. Fate, it seems, is not without a sense of irony. " - Morpheus
"Real men use mspaint for writing code and notepad for designing graphics." - Anna-Jayne Metcalfe
|
|
|
|
|
hmmm yes
Regards,
Sylvester G
sylvester_g_m@yahoo.com
|
|
|
|
|
Ha, excellent!
|
|
|
|
|
Pete O'Hanlon wrote: MayHaveCurves
"That's no moon, it's a space station." - Obi-wan Kenobi
|
|
|
|
|
Maybe it means, "is empty to the untrained eye, but we know it's really not"?
|
|
|
|
|
string currentdate = "Current date and time is " + DateTime.Now.ToString();
StringBuilder sbcurrentdate = new StringBuilder();
sbcurrentdate.Append(currentdate);
return sbcurrentdate;
Regards,
Sylvester G
sylvester_g_m@yahoo.com
|
|
|
|
|
Marvelous, a real beauty. Let me guess what comes after the method call... .ToString()?!?
|
|
|
|
|
sylvesterg wrote: return sbcurrentdate.ToString();
I assume, or does it really returns StringBuilder? Either way... heh.
"Throughout human history, we have been dependent on machines to survive. Fate, it seems, is not without a sense of irony. " - Morpheus
"Real men use mspaint for writing code and notepad for designing graphics." - Anna-Jayne Metcalfe
|
|
|
|
|
I don't get it. Oh well...
|
|
|
|
|
The whole point of using StringBuilder is that it's far more efficient than using "+" to "add" two strings together - the programmer was probably told to use StringBuilder for efficiency, and that was what they came up with
|
|
|
|
|
you caught the code nicely
Regards,
Sylvester G
sylvester_g_m@yahoo.com
|
|
|
|