removing default case requirement?
Steven Schveighoffer
schveiguy at gmail.com
Sun Apr 2 15:27:25 UTC 2023
On 3/31/23 11:20 AM, Steven Schveighoffer wrote:
> Why not? How much does this rule help you, vs. annoy you?
Thanks for all the replies and discussion.
I have realized from all of this that there is a major difference
between `if` and `switch` which justifies the requirement: `switch` can
*only* do single-value comparison. I.e. it has to be the equivalent of
`if(a == b)`, whereas `if` can cover any number of cases or patterns
based on boolean logic and comparisons. This makes it a lot easier to
cover all the cases you need in one go.
`switch` on the other hand, can only cover the cases you specify. In
something like an `int` or even a `byte`, that means full coverage is
unwieldy or near impossible. Even with case range statements, those
actually just get expanded to all the intermediate cases. So forgetting
go cover cases is much more likely.
So I withdraw the suggestion. It also gives me a much better response to
"why does D do this?"
-Steve
More information about the Digitalmars-d
mailing list