I hope this series becomes popular enough for bad developers to notice code like this. Because these code is really what’s out that! I’m serious! Next up, abuse of try-catch. This is how type validation is done. Wonderful, isn’t it? And look at the wonderful booleans associated with the try-catch logic? Doesn’t that just make you cringe?

DateTime newDateStart;
DateTime newDateEnd;
string errorMessage;
int index = 0;
bool isInputValid = true;
bool isSingleDayLeave = true;

try
{
    // dateStart is a string assigned from above this code snippet
    newDateStart = Convert.ToDateTime(dateStart);
}
catch
{
    index++;
    errorMessage += index + ". Date start should be given.<br />";
    isInputValid = false;
}

try
{
    // dateEnd is a string assigned from above this code snippet
    newDateEnd = Convert.ToDateTime(dateEnd);
    isSingleDayLeave = false;
}
catch
{
    isSingleDayLeave = true;
}
// ... more of similar code below.
© 2009 - 2011 JustinLee.sg Suffusion theme by Sayontan Sinha
Stop SOPA!

SOPA breaks our internet freedom!
Any site can be shut down whether or not we've done anything wrong.

Stop SOPA!