shouldn't this code at least trigger a warning?

ketmar via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Apr 30 01:44:18 PDT 2015


On Wed, 29 Apr 2015 07:57:07 -0700, H. S. Teoh via Digitalmars-d-learn
wrote:

> Switch statements in D allow all sorts of abominations, if only you
> would try it. I think it was originally designed to support a particular
> loop idiom (sorry I forgot what it was called, and don't have time to
> look it up right now), but in the process this also opened the door to
> all sorts of nasty infelicities that probably breaks the type system,
> control flow, and many other things. Basically, the block inside a
> switch statement essentially amounts to free-for-all spaghetti code
> where you're free to jump around case labels willy-nilly, declare
> variables and jump over their initializations, break out of loops with
> goto case, or enter into the middle of a loop, and all sorts of other
> crazy things that, ostensibly, you shouldn't be able to do in a language
> like D.

yes, `switch` is one of those legacy cans of worms. i'm afraid that it's 
too late to redesign it, but it would be nice if each `case` will be an 
implicit `{}` block, and `goto case`/`break` will be allowed only as a 
last statement in `case` block. and unlabeled code in `switch` should be 
forbidden to.

but, as i said, it's too late to introduce such breaking change to 
language.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: not available
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20150430/269faee5/attachment.sig>


More information about the Digitalmars-d-learn mailing list