|
|
If you find this funny, you'll love <a href="http://thedailywtf.com/">TheDailyWTF.com</a>[<a href="http://thedailywtf.com/" target="_blank" title="New Window">^</a>]
|
|
|
|
|
This is what I would be used to seeing...
if (lang == "Japanese")
{
msg.BodyEncoding = System.Text.Encoding.UTF8;
msg.SubjectEncoding = System.Text.Encoding.UTF8;
}
else if( lang != "Japanese" )
{
msg.BodyEncoding = System.Text.Encoding.UTF8;
msg.SubjectEncoding = System.Text.Encoding.UTF8;
}
|
|
|
|
|
you forgot the fallback, when all other tests failed:
...
else
{
msg.BodyEncoding = System.Text.Encoding.UTF8;
msg.SubjectEncoding = System.Text.Encoding.UTF8;
}
|
|
|
|
|
Don't repeat yourself...
retry:
if (lang == "Japanese")
{
msg.BodyEncoding = System.Text.Encoding.UTF8;
msg.SubjectEncoding = System.Text.Encoding.UTF8;
}
else if( lang != "Japanese" )
{
lang = "Japanese" ;
goto retry ;
}
(Or something like that; I don't actually know how to do a goto...)
|
|
|
|
|
That's OK - you don't need a GOTO!
while (lang != "Japanese")
lang = "Japanese";
....
Software rusts. Simon Stephenson, ca 1994.
|
|
|
|
|
My current workplace, I saw 2 functions, exactly the same except the name, written by a senior developer, who suppose to overlook the juniors!
Mistake?
Well, those two functions are one after the other, both fit right into one screen [that small the functions are].
|
|
|
|
|
//Updated
Hello everyone
I just want to know cost of
Assignment statement
Isok = false;
and if condition
if(Isok == true)
Isok=false;
Thanks
First One
bool IsOk=false;
while(i < 1000)
{
………….
…………
………….
if(i< 100)
{
IsOk=false;
}
i++;
}
Second
bool IsOk=false;
while(i < 1000)
{
………….
…………
………….
if(IsOk && i< 100)
{
IsOk=false;
}
i++;
}
Life's Like a mirror. Smile at it & it smiles back at you.- P Pilgrim
So Smile Please
modified on Monday, September 27, 2010 4:58 AM
|
|
|
|
|
|
I don't see why you would want/need to check it is True just to set it to false. So i would go with the first option.
Dave
Find Me On: Web| Facebook| Twitter| LinkedIn
CPRepWatcher now available as Packaged Chrome Extension, visit my articles for link.
|
|
|
|
|
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]
|
|
|
|