|
|
|
|
|
by tabtab
2312 days ago
|
|
The C-style switch/case construct is obsolete and awkward, and cleaner alternatives exist, such as VB.net's technique. There is no need for "Break". The following could be added to C-style languages without overlapping with the existing syntax: select(a) {
when 1,2,3 {...}
when 4 {...}
when 5,6 {...}
...
otherwise {...}
}
C# recently added a pattern-matching alternative, but it's still a bit verbose for most needs. |
|
It’s a far cry from general pattern matching (a la Rust, Scheme) but it’s helpful in some circumstances. Otherwise, you can also stick multiple case labels together, i.e.
I don’t see why you need to call the C-style construct obsolete and awkward, though. It works plenty well for enumerations, which is basically what it was designed for. If you need to do something more fancy, if/else if chains always work.