Tuesday, May 17, 2005

 

Most money-minded person I have met lately!!


Tuesday, May 10, 2005

 

Dumb Code - 2

I noticed the following code last week in one of our tools. The user selects some data in the GUI, selects a list of rules that are to be applied on that range, presses "Run rules". The GUI should pass certain parameters to the module below. This is one of the APIs exposed to the GUI by that module.

Why get a string, representing the rule category from GUI, instead of just an integer??

---[ Code snippet ]----------------------------------------------------------------------

// Rule category obtained from GUI
#define RULECATEGORY_1 "Type 1 Rules"
#define RULECATEGORY_2 "Type 2 Rules"
#define RULECATEGORY_3 "Type 3 Rules"
#define RULECATEGORY_4 "Type 4 Rules"
#define RULECATEGORY_5 "Type 5 Rules"
#define RULECATEGORY_6 "Type 6 Rules"
#define RULECATEGORY_7 "Type 7 Rules"
#define RULECATEGORY_8 "Type 8 Rules"


// Constants indicating the rule category
#define CR_1 0
#define CR_2 1
#define CR_3 2
#define CR_4 3
#define CR_5 4
#define CR_6 5
#define CR_7 6
#define CR_8 7
#define CR_9 8

int InitiateRuleChecking (
ORD4 start_index,
ORD4 stop_index,
ORD2 num,
char *category,
ChkStruct &bool_struct,
ORD4 array_size
)
{

int tempCategory = -1;
if(strcmp(category, RULECATEGORY_1) == 0)
{
tempCategory = CR_1;
}
else if(strcmp(category, RULECATEGORY_2) == 0)
{
tempCategory = CR_2;
}
else if(strcmp(category, RULECATEGORY_2) == 0)
{
tempCategory = CR_3;
}
else if(strcmp(category, RULECATEGORY_3) == 0)
{
tempCategory = CR_4;
}
else if(strcmp(category, RULECATEGORY_4) == 0)
{
tempCategory = CR_4;
}
else if(strcmp(category, RULECATEGORY_5) == 0)
{
tempCategory = CR_5;
}
else if(strcmp(category, RULECATEGORY_6) == 0)
{
tempCategory = CR_6;
}
else if(strcmp(category, RULECATEGORY_7) == 0)
{
tempCategory = CR_7;
}
else if(strcmp(category, RULECATEGORY_8) == 0)
{
tempCategory = CR_8;
}
else
{
// Category not defined
AssertErr("Category requested by user not found ");
return -1;
}

// Remaining code...

}

---[ End snippet ]----------------------------------------------------------------------
Indian Bloggers Ring
[ Join | Hub | ? | << | >> ]