04 August, 2005

Nasty legacy code

My current project is to maintain a range of application for a financial/insurance firm. Trying to sort out a bug in some nasty legacy-code (VB.NET) I just came across this piece of code:

If objDataReader(”ID\_QuestionType”) = 1 Then ShowQuestion = ShowQuestionType1(ID\_Question, …)
If objDataReader(”ID\_QuestionType”) = 2 Then ShowQuestion = ShowQuestionType2(ID\_Question, …)
If objDataReader(”ID\_QuestionType”) = 3 Then ShowQuestion = ShowQuestionType3(ID\_Question, …)
If objDataReader(”ID\_QuestionType”) = 4 Then ShowQuestion = ShowQuestionType4(ID\_Question, …)
If objDataReader(”ID\_QuestionType”) = 5 Then ShowQuestion = ShowQuestionType5(ID\_Question, …)
If objDataReader(”ID\_QuestionType”) = 6 Then ShowQuestion = ShowQuestionType6(ID\_Question, …)
If objDataReader(”ID\_QuestionType”) = 7 Then ShowQuestion = ShowQuestionType7(ID\_Question, …)
If objDataReader(”ID\_QuestionType”) = 8 Then ShowQuestion = ShowQuestionType8(ID\_Question, …)
If objDataReader(”ID\_QuestionType”) = 9 Then ShowQuestion = ShowQuestionType9(ID\_Question, …)
If objDataReader(”ID\_QuestionType”) = 10 Then ShowQuestion = ShowQuestionType10(ID\_Question, …)
If objDataReader(”ID\_QuestionType”) = 11 Then ShowQuestion = ShowQuestionType11(ID\_Question, …)
If objDataReader(”ID\_QuestionType”) = 12 Then ShowQuestion = ShowQuestionType12(ID\_Question, …)
If objDataReader(”ID\_QuestionType”) = 13 Then ShowQuestion = ShowQuestionType13(ID\_Question, …)
If objDataReader(”ID\_QuestionType”) = 14 Then ShowQuestion = ShowQuestionType14(ID\_Question, …)
If objDataReader(”ID\_QuestionType”) = 15 Then ShowQuestion = ShowQuestionType8(ID\_Question, …)
If objDataReader(”ID\_QuestionType”) = 101 Then ShowQuestion = ShowQuestionType101(ID\_Question, …)
If objDataReader(”ID\_QuestionType”) = 102 Then ShowQuestion = ShowQuestionType102(ID\_Question, …)

This makes me dry heave! Maybe a little GoF Strategy pattern? What happens when Question type id 103 emerges? Dare I say that the class I found this piece of code in consists of 2826 rows!!

I don’t know what I want with this post, probably nothing just had to get it of my chest.


Tags: