I've recently started on the maintenance of a mature product and littered throughout I see switch statements used like such:
switch (true)
{
case true when object.firstBoolValue:
// do something
break;
case true when object.secondBoolValue:
// do something
break;
case true when object.thirdBoolValue:
// do something
break;
}
Personally, I would have preferred to write it like this:
if (object.firstBoolValue)
// do something
return;
if (object.secondBoolValue)
// do something
return;
if (object.thirdBoolValue)
// do something
return;
// do default
return;
Primary question: which is better for readability? Secondary question: which design (if any) is more performant?