Errors in TDPL

Jonathan M Davis jmdavisProg at gmail.com
Wed Jun 23 09:01:23 PDT 2010


Rory McGuire wrote:

> On Tue, 22 Jun 2010 23:37:59 +0200, Andrei Alexandrescu
> <SeeWebsiteForEmail at erdani.org> wrote:
> 
>> Walter, can we require a semicolon please?
> +1
> 
> With the semi colon missing its as bad as:
> for (;i<100;i++);
>    writeln(i);
> 
> esp. with large amount of code
> 
>> Andrei
> 
> Rory

It's not that bad.

for(; i < 100; ++i);
    writeln(i);

would be a bug (if it were legal) because you'd expect the writeln() to be 
part of the loop when it isn't. The loop wouldn't be run like you'd expect 
it to, and it's hard to catch.

do
{
    ...
} while(test)

does not have that problem. The problem you run into is this:

do
{
  ...
}

while(test)
{
  ...
}

If you're _really_ not paying attention, you'd think that the second set of 
braces started a while loop. But since you'd have to have way more spacing 
than makes sense for it to happen, it becomes way more obvious and is not 
the same level of problem. However, I do think that it _is_ a problem, and 
the above example could definitely be confusing if you're just quickly 
scanning over code.

I don't see any real reason to allow the lack of semicolon, and I do think  
that it's a problem, but I don't think that it's a problem on the same level 
as allowing a semicolon to be used as an empty body for an if statement or 
loop.

- Jonathan M Davis


More information about the Digitalmars-d mailing list