I'm only asking because almost the entire code base I've inherited here, in C# and PHP, looks like this:
if (varOne == flag) {
run_some_sql();
set_some_flag = true;
}
if (varTwo == flag) {
run_some_sql();
set_some_flag = true;
}
if (varThree == flag) {
run_some_sql();
set_some_flag = true;
}
if (varFour == flag) {
run_some_sql();
set_some_flag = true;
}
if (varFive == flag) {
run_some_sql();
set_some_flag = true;
}
if (varSix == flag) {
run_some_sql();
set_some_flag = true;
}
if (varSeven == flag) {
run_some_sql();
set_some_flag = true;
}
if (varEight == flag) {
run_some_sql();
set_some_flag = true;
}
For about ten thousand lines.
I haven't lost my mind, right? Is this bad? There's only about five loops in the entire code base of about 50,000 lines.
I would normally go about this sort of thing by storing the data into an associated array, and loop over that, rather than adding a new if
statement for every variable.
Have I totally lost my mind? Eight people worked on this before me, and I'm seriously worried here. Is there ever a good reason to do this sort of thing?