|
Maybe it involves a costly network or database transaction?
|
|
|
|
|
yes you got it
so what will you prefere?
Life's Like a mirror. Smile at it & it smiles back at you.- P Pilgrim
So Smile Please
|
|
|
|
|
Even if it does involve an expensive operation, with the code structure we can see, i still cannot see how it makes a difference.
If the code before the 'if' checks the isOk to perform the operation then maybe, but if isOK is already true, and you need to set it back to false if i<100, then maybe the whole way the operation is being done need to be reviewed.
If your logic requires for the the operation to continue until i > 100, then it doesn't matter what happens with isOK, or if it is true already. just set it back to false and get on with what you need to do.
I am maybe not explaining very well what i'm trying to say, but i hope you catch my drift.
Dave
Find Me On: Web| Facebook| Twitter| LinkedIn
CPRepWatcher now available as Packaged Chrome Extension, visit my articles for link.
|
|
|
|
|
They both suck.
Isok seems to be handling two conditions. The one hidden in the comments, that could change it. And the less than 100. That's confusing.
In any case You don't need an if.
Isok = I < 100
Would work.
Sorry for caps and formatting, I'm on a phone.
Rd
|
|
|
|
|
At the moment I'm more concerened with the meaning of while(int i=0) . Will it compile? Will it execute the loop?
|
|
|
|
|
PIEBALDconsult wrote: Will it compile? Will it execute the loop?
Yes. No.
|
|
|
|
|
At first, I thought the coding horror was the "while(int i = 0)" (or whatever it was), but I didn't understand why you posted two similar versions. Now that you changed it, I don't understand what the coding horror is at all.
|
|
|
|
|
Maybe the coding horror is premature optimisation? Unless the programmer has determined that this is a bottleneck, the better one is the one that expresses the logic most clearly (the one without the extra test, for my money), not the one with the lowest "cost". And if the programmer has determined that this is a bottleneck, they can use the same tools to find out which is faster.
|
|
|
|
|
Sometimes I shake my head. Found this gem in some stuff I wrote 7 or 8 years ago.
Sleep(15);
I especially like the smiley in the comment.
Chris Meech
I am Canadian. [heard in a local bar]
In theory there is no difference between theory and practice. In practice there is. [Yogi Berra]
|
|
|
|
|
But it does sound like a splendid idea right now
|
|
|
|
|
I saw similar code recently, stuff running on another thread at the time.
It all worked wonderfully until someone ran it from an old, slow, low memory machine where the wait wasn't long enough!
Now where is the GoBackToSleepABitMore() command? It works on my kids.
|
|
|
|
|
Really.. You have to teach me that one. Mine get up at 6:00AM on weekends, even if I make it impossible for them to watch cartoons or play video games.
|
|
|
|
|
keep them up late on friday night usually works. of course you don't get enough sleep either way!
|
|
|
|
|
Hmmm. Did something similar a while ago when I wrote my first multithreading application. It was getting three datasets from a database and needed all three to finish before moving on. Initially, I had the sleep before I got the threads to synchronise properly. However, I forgot to take the sleep out. Application went into Production and only after a complaint a few months later did I investigate and find the gem.
Good thing was that I looked like a hero because I made the application so much quicker. One of these days I'll own up!
|
|
|
|
|
Nah, those are the things we build our reputations on.
Chris Meech
I am Canadian. [heard in a local bar]
In theory there is no difference between theory and practice. In practice there is. [Yogi Berra]
|
|
|
|
|
I had an occasion where Sleep() was required to make something work. We had a third-party library we used to communicate with some USB hardware. The library didn't synchronize properly with the device driver, so you had to follow your calls to the library with Sleep() calls of various durations .
Software Zen: delete this;
|
|
|
|
|
Gary Wheeler wrote: The library didn't synchronize properly with the device driver, so you had to follow your calls to the library with Sleep() calls of various durations.
Hmmm, (pondering whether this Sleep() will fix a BlueTooth sync problem we're experiencing....)
Gary
|
|
|
|
|
[Showing my age!] I remember back when the PC AT came out, with a (WOW!) 80286 clocked at 6 Mhz. You had to write two NOPs after every OUT instruction, I think it was. Otherwise the I/O bus got its tits in a tangle.
Software rusts. Simon Stephenson, ca 1994.
|
|
|
|
|
When a debug message conveys Relief, you're probably
on thin ice.
dbg('Function returning true...');
dbg('Whew.... Its your baby now - messaging');
-Rd
|
|
|
|
|
Similar to this one
TRACE("Shouldn't be able to reach this code! But good luck, though.");
Chris Meech
I am Canadian. [heard in a local bar]
In theory there is no difference between theory and practice. In practice there is. [Yogi Berra]
|
|
|
|
|
MsgBox( "Oops." ) I found this one in something I wrote in my first job out of school.
|
|
|
|
|
I used to do that alot in crazy if else statements that shouldn't have been needed:
Response.Write("Something has gone seriously wrong here, please reboot universe")
|
|
|
|
|
I use a throw with a similar message - mostly on the default of a switch
|
|
|
|
|
Yes, that kind of thing is always a bad sign. Not that I ever did such a thing when I started out!
I do make sure to avoid doing such things now.
Just because the code works, it doesn't mean that it is good code.
|
|
|
|
|
In my first job I was working alongside some guys from an external vendor. Integrating their system into ours and trying to get the whole thing validated by System Test.
One day an error popped up that originated in the Vendors Code:
"The System Has Gone Pear Shaped"
System test weren't impressed.
The guy from the external vendor was summoned, and asked what a more accurate error message would be. I can't remember what it was, but he gave a very detailed, accurate and completely unintelligible response.
To which the head of system test replied...
"And what does that mean? In English?"
To which he replied...
"The system has gone pear shaped."
-Rd
|
|
|
|