On Friday, 31 March 2023 at 15:20:41 UTC, Steven Schveighoffer wrote:
>Why not? How much does this rule help you, vs. annoy you?
[Little OT] I don’t really care. In my experience, a switch
is one of the two cases: Every case leads to a return
or every case leads to a break
. Occasionally, there are cases ending in throw
. When I code C#, which I do occasionally, I almost never use switch
statements, but switch
expressions¹, where every code path necessarily must return a value. The best part about C#’s switch
expressions is that they don’t need (or even allow for) break
. I consider switch
statements like goto
: It’s there when you need it, but it shouldn’t be your first attempt.
As D implemented DIP 1043 Shortened Method Syntax,² it seems reasonable to also implement switch
expressions in D much alike C#’s.
¹ https://learn.microsoft.com/en-US/dotnet/csharp/language-reference/operators/switch-expression
² https://github.com/dlang/DIPs/tree/master/DIPs