I’ve been messing with this bit of code for over an hour trying to rearrange it different ways. Is there any easier way to write it?
if x is not Number ;// if x is string
{
if y is not Number ;// x, y both strings
{
Eval(x)
Eval(y)
return
}
else ;// x is string, y is Number
{
Eval(x)
Scale(y)
return
}
}
else if y is not Number ;// x is Number, y is string
{
Scale(x)
Eval(y)
return
}
else ;// both are numbers
{
Scale(x)
Scale(y)
return
}
It looks like you want to
Evalstrings andScalenumbers. Instead of having four explicit cases (which would become eight with three variables), handle each case forxandyindependently:Or, better yet, you can push
Eval/Scaleinto a utility method:…and then use it…
If you pick good method names, then creating a utility method makes the code more readable and helps you avoid copy-and-paste repetition.