Re:My Favourite Diff
by Supermancho on Monday April 06, 2020 @04:11AM
(#22791753)
> Most people treat switch as a peculiar form of match (or cond or whatever)
Completely made up switch illustrates how I use it in every language if I can...Go has a succinct version of this.
switch(True) {
case ($x == 1):
$x++;
break;
case ($x > 3):
$x--;
break;
default:
break;
}
Re:My Favourite Diff
by edflsafoiewq on Monday April 06, 2020 @08:57AM
(#22793275)
Why? It's longer, more complex, and more highly indented than a normal if-elif-else.
Most people treat switch as a peculiar form of match (or cond or whatever), probably because this would usually be much more useful to have than a computed goto, and in many derivative languages they've put in weird additions that seem to be an attempt to drag it halfway to that, things that don't really make any sense in C, like allowing dynamic expressions in the cases (such as your example), or forcing all cases to be at the top level.
(I feel like I write a lot of "in defense of switch" comments on HN...)