removing default case requirement?

Steven Schveighoffer schveiguy at gmail.com
Fri Mar 31 21:24:25 UTC 2023


On 3/31/23 2:40 PM, Sebastiaan Koppe wrote:
> On Friday, 31 March 2023 at 18:30:27 UTC, Steven Schveighoffer wrote:
>> Do you feel the same about if statements without `else`? Why is it 
>> different?
>>
> 
> If statements are rather binary, and it is easy to understand the two 
> paths.
> 
> Switches often have more than 2 cases, and its easier to forget one.

Complex if conditions are not "binary". I find it just as easy to forget 
a clause in an if statement that does the right thing.

> 
> Also consider refactoring. With switches I might add or rename or 
> replace one of the values, which doesn't happen with if statements.

If you "forget a case statement", or refactor it, forcing you to write 
`default: break;` doesn't fix that.

-Steve


More information about the Digitalmars-d mailing list