switch()

Ary Borenszweig ary at esperanto.org.ar
Thu Feb 20 09:27:08 PST 2014


On 2/20/14, 1:53 PM, Manu wrote:
> On 21 February 2014 01:20, Steven Schveighoffer <schveiguy at yahoo.com
> <mailto:schveiguy at yahoo.com>> wrote:
>
>     On Thu, 20 Feb 2014 10:13:27 -0500, Daniel Murphy
>     <yebbliesnospam at gmail.com <mailto:yebbliesnospam at gmail.com>> wrote:
>
>         "Steven Schveighoffer"  wrote in message
>         news:op.xbk44onleav7ka at __stevens-macbook-pro.local...
>
>             What I really would be curious about is if in most D code,
>             you see a lot more default: break; than default: assert(0);
>
>
>         I just did a quick git-grep on the compiler source (not D, but
>         all switches do have a default thanks to the d port)
>
>         With 707 "default:"s 68 had a break on either the same or next
>         line, and 249 had an assert(0).
>
>         On phobos I get 22 assert(0)s vs 10 breaks with 147 defaults
>
>         With druntime i get 24 assert(0)s + 5 error();s vs 11 breaks
>         with 64 defaults.
>
>
>     Good data, but I was more thinking of people who use D, not the core
>     language. The core language's developers have different behaviors
>     than standard users. I'm not dismissing this data, but I would like
>     to see more application statistics.
>
>
> In my little app:
>   17 default: break;
>   1 default: assert(0); ... and I just realised it should have been a
> final switch() anyway... so now there's 0.

Did you put those "default: break;" because:

1. The compiler told it to do so.
2. You already know the compiler will tell you, so you put it before 
that happens.

In the cases where it was "1.", did it make you think whether you needed 
to handle the default case?



More information about the Digitalmars-d mailing list