The empty statement ";" - when is it useful?

Daniel Keep daniel.keep.lists at gmail.com
Tue Jul 28 10:49:32 PDT 2009


Andrei Alexandrescu wrote:
> Bill Baxter wrote:
>> On Tue, Jul 28, 2009 at 12:09 AM, Don<nospam at nospam.com> wrote:
>>>> Walter once claimed that it's useful for automatically generated code.
>>>> Though I'm still not quite sure how.
>>> Yes. He's recently the claimed the same thing about the comma
>>> operator, but
>>> I don't buy that argument. I've never needed to use either of them
>>> myself.
>>> (In the case of comma, sure it works as a sequence point when you
>>> have: a,b,
>>> return a; but it doesn't work for a,b, return b; which is 50% of the
>>> cases.
>>> I think it's a fallacious argument). Interestingly CommaExpression
>>> doesn't
>>> seem to be defined anywhere in the D spec.
>>
>> You meant to say it doesn't work for a,b, return a;  right?
>> And I don't think that would be 50% of the cases.  a,b,return b seems
>> much more common.
>>
>> But either way the argument is ridiculous.  It doesn't need to be as
>> basic an operator as a single comma just for the sake of making code
>> generation easier.
> 
> I agree. Walter also mentioned the code generation argument in a
> conversation with me, fully expecting something like "hell yeah" from
> me, but was disappointed :o). If he were right and the comma operator
> would be a net win for better code generation, it would be a net win for
> better handwritten code. But it's not for either; it is some win, but
> minor.
> 
> Anyway, if I had my way I'd eliminate the empty statement ";". It's just
> uselessly hanging in there. It adds half a page total to TDPL just
> because I must first define it and then explain for all of if, while,
> switch, for, foreach... that they can't control an empty statement. If
> the empty statement didn't exist in the first place, I wouldn't be
> wasting readers' time.
> 
> BTW, the use of ";" in foreach is not a problem; that use could be
> easily defined as sheer punctuation.
> 
> 
> Andrei

U comma(T,U)(T a, U b) { return b; }

Is there any reason you couldn't use something like that?



More information about the Digitalmars-d mailing list