Hey!
This can be taken as a more-basic or more-advanced question depending, but I have a method that contains a switch statement:
case CurrentInputEvent.InputHeld:
if (_inputHeld_inh.ignoreState)
{
if (_hover_inh.ignoreState)
{
if (_normal_inh.ignoreState)
{
if (!throw_Error002)
{
throw_Error002 = true;
Debugging.Error002_IgnoringTooManyEventStates("Normal");
return _normal_inh;
}
else return _normal_inh;
}
else return _normal_inh;
}
else return _hover_inh;
}
else return _inputHeld_inh;
Not so pretty, right? I mean it does everything that I want it to do. Nothing more, and nothing less. I may have something wrong with me, but I don’t see a way I can optimize this any further and maintain the same functionality.
WHAT I WANT TO ACCOMPLISH:
If one type is ignored, i want it to get the next one and the next one and the next one UNTIL there comes a point when it gets the type that isn’t ignored.
I have about 15 states to switch through in the “CurrentInputEvent” enum, and each will look something like this. This right here is 20 lines (if I counted to 20 right). 20 x 15 is a lot, especially if there are other cases that will be longer than this.
I never used goto before because I heard it was evil, but does anyone have any concrete evidence that something that looks like:
case 1:
{
if (!lol)
goto case 2;
break;
}
case 2:
{
if (!lol)
goto case 3;
break;
}
case 3:
{
if (!lol)
goto case 4;
break;
}
case 4:
{
if (!lol)
goto case 5;
break;
}
case 5:
if (!lol)
goto default;
break;
is CRIMINAL compared to what I posted originally? Personally I find it to me more concise, line-saving, and more readable.
As I’m working on increasing performance at the moment, if any red flags fly up that “goto is super duper performance heavy” then I’ll have to make the 400 lines of code. With goto I might have 50-60 lines.
Apologies that this is only partially Unity-related, but I’m tired of reading all of the same hate on the goto word with the same single reason: IT’S NOT GOOD PROGRAMMING PRACTICE!