CodeSOD: It's For DIVision

This post was originally published on this site

The Daily WTF

We’ve discussed the evil of the for-case pattern in the past, but Russell F offers up a finding which is an entirely new riff on this terrible, terrible idea.

We’re going to do this is chunks, because it’s a lot of code.

protected void setDivColor() { List<HtmlControl> Divs = new List<HtmlControl>(); HtmlControl divTire1Det = divShopCart.FindControl(“divTire1Det”) as HtmlControl; if (divTire1Det.Visible) { Divs.Add(divTire1Det); } HtmlControl divTire2Det = divShopCart.FindControl(“divTire2Det”) as HtmlControl; if (divTire2Det.Visible) { Divs.Add(divTire2Det); } …

So, this method starts with a block of C# code which tries to find different elements in the HTML DOM, and if they’re currently visible, adds them to a list. How many elements is it finding? If I counted correctly (I didn’t count correctly), I see 13 total. Many of them are guarded by additional if statements:

if (!bMAlignAdded) { HtmlControl divManufAlign_Add = divShopCart.FindControl(“divManufAlign_Add”) as HtmlControl; if (divManufAlign_Add.Visible) { Divs.Add(divManufAlign_Add); } }

To read the full article click on the 'post' link at the top.