So I inherited a big project and I spent a little time understanding the following snippet. I post it here cause I'm bored and as an example of how not to code.
Notice the especially nice unreachable code at the end. So I change it to this:
The guy who wrote the original is a professional programmer from Poland. All of his code is like this. I've never seen so many freaking goto's in C++ code. It's a nightmare.
Code:
next_try:
if( nPingCallCnt < PING_MAX_AMOUNT && IPList.GetCount())
{
Sleep(PING_REPLAY_TIMEOUT);
nPingCallCnt++;
}
else
{
pCliPage->SetPingThreadStatus(PINGTHREADSTATUS_READY);
return 0;
}
for(i=0; i<IPList.GetCount(); i++)
{
// do stuff
}
RemoveIfEmptyIP(&IPList,&AppList,&PortList);
goto next_try;
pCliPage->SetPingThreadStatus(PINGTHREADSTATUS_READY);
return 0;
Notice the especially nice unreachable code at the end. So I change it to this:
Code:
// Wait for 3 seconds, or until everyone we pinged has replied
while (nPingCallCnt < PING_MAX_AMOUNT && IPList.GetCount())
{
Sleep (PING_REPLY_TIMEOUT); // wait 1 second
nPingCallCnt++;
// Check for responses
for (i = 0; i < IPList.GetCount(); i++)
{
// do stuff
}
// Remove anyone who replied
RemoveIfEmptyIP(&IPList,&AppList,&PortList);
}
pCliPage->SetPingThreadStatus(PINGTHREADSTATUS_READY);
return 0;
The guy who wrote the original is a professional programmer from Poland. All of his code is like this. I've never seen so many freaking goto's in C++ code. It's a nightmare.