Should the 2.054 feature about warning on implicit fallthrough

Timon Gehr timon.gehr at gmx.ch
Wed Sep 14 14:42:58 PDT 2011


On 09/14/2011 10:51 PM, bearophile wrote:
> Timon Gehr:
>
>> I think it is a bit mean to say the whole semantics is a mess,
>
> The original C design is a mess with several traps, and successive things added in D to the switch have increased the mess, they were designed from very narrow points of view, with a lack of global vision:
>
> 1) The case x: .. case y: syntax is ugly, and it doesn't respect the semantics of the .. in D that means a range open on the right.
>
That's subjective of course. It does not strike me as particularly ugly. 
(if you'd rather see case x .. y+1:, I think that is exceptionally 
ugly). The fact that the last case is included is a move to make it more 
useful. What would you suggest?


> 2) The introduction of final switches is badly designed and not complete, so the safety of the situation is not improved:
> http://d.puremagic.com/issues/show_bug.cgi?id=5713
>

Yah, that is quite messy, but I think that can be fixed.

> 3) The recent improvements (that are patches on the stupid semantics of the C switch) are buggy and need a patch:
> https://github.com/D-Programming-Language/dmd/pull/370

QOI issue, not a fundamental design flaw. I am sure the patch will be 
applied.

>
> Switch is too much limited, ignoring other needs:
> http://d.puremagic.com/issues/show_bug.cgi?id=596
>

I agree that it would be nice for switch to work on other types.

The other needs are better addressed by the introduction of a match 
expression.

> I'll never agree that the C switch is well (or even "well enough") designed. Even a simple language as Pascal gets the case-of statement better than C.
>

'C switch' means 'jump table'. It does do that perfectly. ;)

>
>> switch statements and gotos provide nice means of writing highly
>> efficient code that still looks somewhat structured.
>
> I'd like computed gotos in D. I have discussed with Walter often about this, but he doesn't listen much on this.
>

+1.

>
>> Well, yes, but that is as expected. Would you expect a fall through
>> error on this code?
>
> Have you run that code?
>

What is your point?





More information about the Digitalmars-d-learn mailing list