Errors in TDPL

Jonathan M Davis jmdavisProg at gmail.com
Tue Jun 22 15:12:13 PDT 2010


Andrei Alexandrescu wrote:

> 
> Walter, was that intentional? The grammar has no semicolon but the
> example does. That makes the example wrong because you agreed there is
> no solitary semicolon statement in D, and TDPL does mention that.
> 
> IMHO the semicolon makes for more robust code. Consider:
> 
> do
> {
>      ... lotsa code ...
> }
> while (fun(i))
> ++i;
> 
> A maintainer might see the while and conclude that ++i; was meant to be
> the loop, indent it, and call it a day. The absence of the semicolon
> thus created a contextual dependency on the presence of the "do" keyword
> upstream.
> 
> Walter, can we require a semicolon please?
> 
> 
> Andrei

I have zero problem requiring a semicolon (I'd prefer it actually), but I 
believe that a lone semicolon is generally a perfectly valid statement in D 
as long as it's not where optional braces could be. Per the grammar:

Statement:
    ;
    NonEmptyStatement
    ScopeBlockStatement

I believe that all the constructs with optional braces have a 
ScopBlockStatement for their body and therefore can't have a lone semicolon. 
But a statement by itself can be a lone semicolon. Though why you'd do that, 
I don't know. The only place that I've run into that being useful has been 
with macros (which don't exist in D).

- Jonathan M Davis


More information about the Digitalmars-d mailing list