Tuesday, March 06, 2007

Coding For Dummies

Some of you have already heard me vent about this already, but I just think it's too good not to share with everyone else. So, anyway I had to deal with some really horribly written code recently. I mean this is the sort of stuff that you simply cannot make up. It really is that bad.

A person might need a loop using some kind of counter. But, no one needs what I had the privilege of dealing with shown below for your entertainment. The if - else if chain was a part of some function that was ironically being called in some sort of loop. In any case, enjoy.

// global booleans
bool firstTime = true;
bool secondTime = false;
bool thirdTime = false;
bool fourthTime = false;

if( firstTime )
{
firstTime = false;
secondTime = true;
// do some stuff
}
else if( secondTime )
{
secondTime = false;
thirdTime = true;
// do same exact stuff as before
}
else if( thirdTime )
{
thirdTime = false;
fourthTime = true;
// do same exact stuff as before
}
else if( fourthTime )
{
// do same exact stuff as before
}

To make matters even worse, this code needs to be expanded at some point, most likely with a variable number of iterations. Talk about a nightmare. Oh, this really is just the tip of the iceberg, but I think I've said enough. It amazes me that anyone can possibly believe that coding in this manner is logical or effective.

No comments:

Quantcast