Article 50Y8V CodeSOD: Deep VB

CodeSOD: Deep VB

by
Remy Porter
from The Daily WTF on (#50Y8V)

Thomas had an application which was timing out. The code which he sent us has nothing to do with why it was timing out, but it provides a nice illustration of why timeouts and other bugs are a common "feature" of the application.

The codebase contains 9000+ line classes, functions with hundreds of lines, and no concept of separation of function. So, when someone needed to look at an account number and decide if that account needs special handling, this is what they did:

 For i As Integer = 0 To R - 1 If DataSet.Tables(0).Rows(i)("Code") = Code Then If Not IsDBNull(DataSet.Tables(0).Rows(i)("Estimate")) Then If DataSet.Tables(0).Rows(i)("Estimate") <> "E" Then If Not (IsDBNull(DataSet.Tables(0).Rows(i)("Code2"))) Then If Not (DataSet.Tables(0).Rows(i)("Code2").contains("XX")) Then 'does not perform the test on XX accounts If Not (DataSet.Tables(0).Rows(i)("Code2").contains("YYY")) Then If Not (DataSet.Tables(0).Rows(i)("Code2") = "ZZZZZZ") Then If Not (DataSet.Tables(0).Rows(i)("Code2").contains("ZZZ")) Then If (Not (DataSet.Tables(0).Rows(i)("Code2").Contains("CC"))) Or (Not (DataSet.Tables(0).Rows(i)("Code2").Contains("cc"))) Then If Not (DataSet.Tables(0).Rows(i)("Code2") = "AAAAAA") Then If Not (DataSet.Tables(0).Rows(i)("Code2").StartsWith("BB")) Then If Not (DataSet.Tables(0).Rows(i)("Code2").Contains("BBBB")) Then If Not (IsDBNull(DataSet.Tables(0).Rows(i)("Location"))) Then Dim tempLocation As String = DataSet.Tables(0).Rows(i)("Location") If Not (tempLocation.Contains("XX")) Then 'does not perform the test on XX accounts If Not (tempLocation.Contains("YYY")) Then If Not (tempLocation = "ZZZZZZ") Then If Not (DataSet.Tables(0).Rows(i)("Location").contains("ZZZ")) Then If tempLocation = "CCCCCC" Or tempLocation = "CCCCCC" Then GoTo Skip Else If Not (DataSet.Tables(0).Rows(i)("Location") = "AAAAAA") Then If Not (DataSet.Tables(0).Rows(i)("Location").StartsWith("BB")) Then If Not (DataSet.Tables(0).Rows(i)("Location").Contains("BBBB")) Then If DataSet.Tables(0).Rows(i)("Date") > LastMonth Then LastMonth = DataSet.Tables(0).Rows(i)("Date") If Not IsDBNull(DataSet.Tables(0).Rows(i)("Present")) Then LastReading = DataSet.Tables(0).Rows(i)("Present") Else LastReading = 0 End If End If End If End If End If End If End If End If End If End If End If End If End If End If End If End If End If End If End If End If End If End If End Ifskip: Next

I don't know what this code does. I don't really want to. It's a stack of if statements so deep that it provides a habitat for monothalameans.

The real treat, though, is that hidden goto, which sort circuits the loop. Thomas didn't know that labels, in VB.Net, were scoped to functions, so you can re-use the same label, skip as often as you like, and don't worry, the developer who wrote this did. skip:s all over the place.

buildmaster-icon.png [Advertisement] BuildMaster allows you to create a self-service release management platform that allows different teams to manage their applications. Explore how! TheDailyWtf?d=yIl2AUoC8zAgz0_BdiniwU
External Content
Source RSS or Atom Feed
Feed Location http://syndication.thedailywtf.com/TheDailyWtf
Feed Title The Daily WTF
Feed Link http://thedailywtf.com/
Reply 0 comments