Switch-case made less buggy, now with PATCH!

Don nospam at nospam.com
Sun Nov 22 15:26:06 PST 2009


Chad J wrote:
> Don wrote:
>> Chad J wrote:
>>> Don wrote:
>>>> I think you've just created the strongest argument AGAINST this feature:
>>>> that it makes it too hard for machine-generated code.  Forget the !:
>>>> hack. No chance.
>>>>
>>> If that's the strongest argument, then this is cake.  I'll go through
>>> Phobos and insert goto case's by hand if that's what needs to happen.
>>>
>>> Most of the fallthrough I saw was stuff like this:
>>>
>>> case '1': case '2': case '3':
>>> case '4': case '5': case '6':
>>> case '7': case '8': case '9':
>>> ...etc...
>>> break;
>> You didn't read my post. That is NOT bug-prone. I don't think anyone
>> EVER makes bugs in that form.
>> It's actually got very little in common with a true fall-through. Real
>> fallthrough involves a 'goto' by stealth: the case introduces an entry
>> point in the middle of a code block.
>>
> 
> I DID read your post.  I'm not saying that it is bug prone.  I was just
> demonstrating how it is not very hard to fix code that is broken by
> forbidding fallthrough.  I'm explaining why I don't understand how the
> "machine-generated" code thing is such a big issue.
> 
>>>> The argument for it comes down to this: "fallthrough is very rare and
>>>> therefore, most uses of fallthrough are bugs".  
>>> Not as I remember.
>>>
>>> "inline assembly is very rare and therefore, most uses of inline
>>> assembly are bugs."
>>> Such reasoning wouldn't get inline asm removed either.  Fallthrough is
>>> not bad because it is rare.  I think that's only mentioned because the
>>> rarity makes it easier to let go of fallthrough altogether.
>> Not at all. Requiring changes to existing code is a very big negative to
>> any proposal. If the number of changes required is small,
>>
> 
> continue...
> 
>>> But I think you've just gone about
>>>> this wrong way. 
>>> Perhaps.  I'll find out for myself.
>> I doubt it.
>>
> 
> Ow.
> 
>> You've missed the point. Andrei made a proposal for eliminating
>> accidental fallthrough bugs. It didn't involve any new syntax, and
>> changed very little existing code. Anything which violates either of
>> those things has very little chance of acceptance. You've done a patch
>> which completely ignores his proposal, and which violates both.
>>
> 
> Sorry I didn't know about Andrei's proposal.  Buried in the NG.

I'm surprised about that. It's what all the recent posts were based on!

> 
> Why didn't you just say that Andrei made another proposal and that
> you're peeved I didn't use it?

I'm not peeved.

>> The comment about the auto-generated code raises an aspect which hadn't
>> been considered in the original proposal.
> 
> I also don't get this argument against requiring code changes.  D2 will
> break your code and is allowed to do so for the sake of progress and
> long term good.  Everyone knows this.

Yes, but it still needs a good reason to break with C/C++/D1 in a way 
which increases language complexity.



More information about the Digitalmars-d mailing list