switch()

Steven Schveighoffer schveiguy at yahoo.com
Tue Feb 18 09:52:07 PST 2014


On Tue, 18 Feb 2014 12:26:36 -0500, Daniel Murphy  
<yebbliesnospam at gmail.com> wrote:

> "Steven Schveighoffer"  wrote in message  
> news:op.xbhkirppeav7ka at stevens-macbook-pro.local...
>
>> My point though, is that the change to require default gains you  
>> nothing except annoyed programmers. Why put it in?
>
> It only gains you nothing if you respond to the error by mindlessly  
> putting a default: break; in.
>

It may not be mindless. Most people who want to handle the default case do  
it. It's usually not so much "I didn't think of handling other values,"  
it's more "I never expect other values to come in, go away annoying  
compiler error."

> Here the right and wrong choice are about equal difficulty - trivial.  I  
> think complaints about typing those extra couple dozen keystrokes are on  
> the same level as "why do I have to put these ';'s everywhere" and  
> "'immutable' has too many letters".

I think it's the same as saying you have to always have an else clause  
after an if statement, even if it's "else {}"

-Steve


More information about the Digitalmars-d mailing list