WTF!

I've just seen some of the worst code of my life... fortunately it was from an AutoGenerated application.

Lets start with this

pValue = Utility.GetParam("issue_id");Response_issue_id.Value = pValue;
if(Session["UserID"]!=null)
    pValue = Session["UserID"].ToString();   
else
    pValue="";Response_user_id.Value = pValue;
    pValue = Utility.GetParam("assigned_to");  

Notice that after the else, you will see that there are two statements on one line. Due to the fact that there is no bracket, the 2nd statement will also be executed when the condition was met as well.

After that we see loads of

pValue = Utility.GetParam("assigned_to");
try 
{
    Response_assigned_to.SelectedIndex=Response_assigned_to.Items
        .IndexOf(Response_assigned_to.Items.FindByValue(pValue));
}
catch{} 
pValue = Utility.GetParam("priority_id");
try 
{
    Response_priority_id.SelectedIndex=Response_priority_id.Items
        .IndexOf(Response_priority_id.Items.FindByValue(pValue));
}
catch{} 

Where this pattern is repeated for about a dozen fields. Don't run this code with "Break when an exception is thrown" switched on.

However my personal favourite is

Decimal.Parse(CCUtility.GetFormattedNumeric(mydec,CCUtility.defaultReturnedNumeric.BlankString )); 

The point here is that CCUtility.GetFormattedNumeric attempts to parse a string into a numeric (again with a try catch around a Decimal.Parse) and then returns ToString("0.#####"). If the string isn't a number then it returns the 2nd argument, which is CCUtility.defaultReturnedNumeric.BlankString but of course that fails the Decimal.Parse. Shame they didn't use the alternative value CCUtility.defaultReturnedNumeric.Zero and saved two exceptions being thrown.

Comments (3) -

robert_
robert_
5/29/2009 7:49:55 PM #

Oh my god, I've seen crappy code, but that really takes the cake!
Was it Visual Studio (or..?) that generated such god-awful code?

robert_

alski
alski
6/1/2009 12:04:19 PM #

No, it was a third party product, and admittedly it was for DotNet 1.1, but still I would have expected something a little more legible.

robert_
robert_
6/1/2009 11:26:02 PM #

Y...eeeah. that kind of is like somebody noticing the Emperor's got no clothes on Tong
By the way- I found 'ya via CodeProject; nice articles Laughing

You know, an interesting project would be to reinvent the NT console in managed code (using GDI+). Maybe you could get somewhat further on it than I have in the past month or so Tong

robert_

Add comment

  Country flag


  • Comment
  • Preview
Loading