Jump to page: 1 2 3
Thread overview
Extra semicolons, Errors or not ?
Feb 20, 2005
Derek Parnell
Feb 20, 2005
Matthew
Feb 21, 2005
Regan Heath
Feb 21, 2005
Regan Heath
Feb 21, 2005
brad
Feb 21, 2005
Regan Heath
Feb 21, 2005
Matthew
Feb 21, 2005
Regan Heath
Feb 21, 2005
brad
Feb 21, 2005
Regan Heath
Feb 21, 2005
Manfred Nowak
Feb 21, 2005
Regan Heath
Feb 21, 2005
Matthew
Feb 21, 2005
John Reimer
Feb 21, 2005
Regan Heath
Feb 21, 2005
zwang
Feb 21, 2005
John Reimer
Was: Extra semicolons... Flame or not ?
Feb 21, 2005
MicroWizard
Feb 21, 2005
Regan Heath
Feb 21, 2005
Georg Wrede
Feb 20, 2005
Matthew
Feb 21, 2005
zwang
Feb 21, 2005
Thomas Kühne
February 20, 2005
Are any of these extra semicolons really errors ?

> void f()
> {
> 
> };
> 
> class C
> {
> 
> };
> 
> struct S
> {
>   char c;
> };
> 
> union U
> {
>   char c;
> };
> 
> void main()
> {
>   if (false)
>   {
> 
>   };
> 
>   foreach(char c; "")
>   {
> 
>   };
> 
>   ;
>   null;
> }

They all pass the current D compiler silently...

--anders

PS. Not the "char c;" one, but the rest of them.
February 20, 2005
On Mon, 21 Feb 2005 00:22:49 +0100, Anders F Björklund wrote:

> Are any of these extra semicolons really errors ?
> 
>> void f()
>> {
>> 
>> };
>> 
>> class C
>> {
>> 
>> };
>> 
>> struct S
>> {
>>   char c;
>> };
>> 
>> union U
>> {
>>   char c;
>> };
>> 
>> void main()
>> {
>>   if (false)
>>   {
>> 
>>   };
>> 
>>   foreach(char c; "")
>>   {
>> 
>>   };
>> 
>>   ;
>>   null;
>> }
> 
> They all pass the current D compiler silently...
> 

Not to me ;-) But a naked semi-colon and the 'null;' is fairly meaningless to point where one may think that the coder has made a mistake.

However note that

   if (true);

   foreach(char c; "");

   while(true);

are compiler errors.

-- 
Derek
Melbourne, Australia
21/02/2005 10:35:03 AM
February 20, 2005
They all look ok to me

"Anders F Björklund" <afb@algonet.se> wrote in message news:cvb649$qva$1@digitaldaemon.com...
> Are any of these extra semicolons really errors ?
>
>> void f()
>> {
>>
>> };
>>
>> class C
>> {
>>
>> };
>>
>> struct S
>> {
>>   char c;
>> };
>>
>> union U
>> {
>>   char c;
>> };
>>
>> void main()
>> {
>>   if (false)
>>   {
>>
>>   };
>>
>>   foreach(char c; "")
>>   {
>>
>>   };
>>
>>   ;
>>   null;
>> }
>
> They all pass the current D compiler silently...
>
> --anders
>
> PS. Not the "char c;" one, but the rest of them.


February 20, 2005
"Derek Parnell" <derek@psych.ward> wrote in message news:fewqzt2viqdl.btneu9e85pr2$.dlg@40tude.net...
> On Mon, 21 Feb 2005 00:22:49 +0100, Anders F Björklund wrote:
>
>> Are any of these extra semicolons really errors ?
>>
>>> void f()
>>> {
>>>
>>> };
>>>
>>> class C
>>> {
>>>
>>> };
>>>
>>> struct S
>>> {
>>>   char c;
>>> };
>>>
>>> union U
>>> {
>>>   char c;
>>> };
>>>
>>> void main()
>>> {
>>>   if (false)
>>>   {
>>>
>>>   };
>>>
>>>   foreach(char c; "")
>>>   {
>>>
>>>   };
>>>
>>>   ;
>>>   null;
>>> }
>>
>> They all pass the current D compiler silently...
>>
>
> Not to me ;-) But a naked semi-colon and the 'null;' is fairly
> meaningless
> to point where one may think that the coder has made a mistake.
>
> However note that
>
>   if (true);
>
>   foreach(char c; "");
>
>   while(true);
>
> are compiler errors.

I presume that one needs to do

    if(true)
    {}

    foreach(char c; "")
    {}

    while(true)
    {}

??



February 21, 2005
Yep, or, in the more common cases:

foreach (char c; "")
   continue;

while (true)
   continue;

Which makes it a lot cleaner and more readable imho (but obviously cannot be done for if.)

-[Unknown]


> "Derek Parnell" <derek@psych.ward> wrote in message news:fewqzt2viqdl.btneu9e85pr2$.dlg@40tude.net...
> 
>>On Mon, 21 Feb 2005 00:22:49 +0100, Anders F Björklund wrote:
>>
>>
>>>Are any of these extra semicolons really errors ?
>>>
>>>
>>>>void f()
>>>>{
>>>>
>>>>};
>>>>
>>>>class C
>>>>{
>>>>
>>>>};
>>>>
>>>>struct S
>>>>{
>>>>  char c;
>>>>};
>>>>
>>>>union U
>>>>{
>>>>  char c;
>>>>};
>>>>
>>>>void main()
>>>>{
>>>>  if (false)
>>>>  {
>>>>
>>>>  };
>>>>
>>>>  foreach(char c; "")
>>>>  {
>>>>
>>>>  };
>>>>
>>>>  ;
>>>>  null;
>>>>}
>>>
>>>They all pass the current D compiler silently...
>>>
>>
>>Not to me ;-) But a naked semi-colon and the 'null;' is fairly meaningless
>>to point where one may think that the coder has made a mistake.
>>
>>However note that
>>
>>  if (true);
>>
>>  foreach(char c; "");
>>
>>  while(true);
>>
>>are compiler errors.
> 
> 
> I presume that one needs to do
> 
>     if(true)
>     {}
> 
>     foreach(char c; "")
>     {}
> 
>     while(true)
>     {}
> 
> ??
> 
> 
> 
February 21, 2005
On Sun, 20 Feb 2005 17:07:59 -0800, Unknown W. Brackets <unknown@simplemachines.org> wrote:
> Yep, or, in the more common cases:
>
> foreach (char c; "")
>     continue;
>
> while (true)
>     continue;
>
> Which makes it a lot cleaner and more readable imho (but obviously cannot be done for if.)
>
> -[Unknown]

<snip rest of upside down reply>

Or we could add a "noop" expression, to more exactly specify the programmers intent.
eg.

foreach(char c; "") noop;
while(true) noop;
if (true) noop;

Regan
February 21, 2005
I agree.  They are harmless anyway.


Matthew wrote:
> They all look ok to me
> 
> "Anders F Björklund" <afb@algonet.se> wrote in message news:cvb649$qva$1@digitaldaemon.com...
> 
>>Are any of these extra semicolons really errors ?
>>
>>
>>>void f()
>>>{
>>>
>>>};
>>>
>>>class C
>>>{
>>>
>>>};
>>>
>>>struct S
>>>{
>>>  char c;
>>>};
>>>
>>>union U
>>>{
>>>  char c;
>>>};
>>>
>>>void main()
>>>{
>>>  if (false)
>>>  {
>>>
>>>  };
>>>
>>>  foreach(char c; "")
>>>  {
>>>
>>>  };
>>>
>>>  ;
>>>  null;
>>>}
>>
>>They all pass the current D compiler silently...
>>
>>--anders
>>
>>PS. Not the "char c;" one, but the rest of them. 
> 
> 
> 
February 21, 2005
I would think that most compilers would be able to tell this:

while (true)
{
}

Is the same as this:

while (true)
	continue;

So a "noop" wouldn't be required... and, in most cases, when you do:

if (true)
{
}

Well, I can only imagine that being useful for an else/else if simlpification, which is ugly imho and hopefully is optimized out anyway.

I can't really think of a case where a "noop" would be required... and anyway, couldn't you do this:

if (true)
	0;

-[Unknown]


> On Sun, 20 Feb 2005 17:07:59 -0800, Unknown W. Brackets  <unknown@simplemachines.org> wrote:
> 
>> Yep, or, in the more common cases:
>>
>> foreach (char c; "")
>>     continue;
>>
>> while (true)
>>     continue;
>>
>> Which makes it a lot cleaner and more readable imho (but obviously  cannot be done for if.)
>>
>> -[Unknown]
> 
> 
> <snip rest of upside down reply>
> 
> Or we could add a "noop" expression, to more exactly specify the  programmers intent.
> eg.
> 
> foreach(char c; "") noop;
> while(true) noop;
> if (true) noop;
> 
> Regan
February 21, 2005
Matthew wrote:

| "Anders F Björklund" <afb@algonet.se> wrote in message
| news:cvb649$qva$1@digitaldaemon.com...
|
|>Are any of these extra semicolons really errors ?
|>
|>
|>>void f()
|>>{
|>>
|>>};
|>>
|>>class C
|>>{
|>>
|>>};
|>>
|>>struct S
|>>{
|>>  char c;
|>>};
|>>
|>>union U
|>>{
|>>  char c;
|>>};
|>>
|>>void main()
|>>{
|>>  if (false)
|>>  {
|>>
|>>  };
|>>
|>>  foreach(char c; "")
|>>  {
|>>
|>>  };
|>>
|>>  ;
|>>  null;
|>>}
|>
|>They all pass the current D compiler silently...
|>
|
| They all look ok to me
|


http://digitalmars.com/d/statement.html#expression
# Expressions that have no affect, like (x + x), are illegal in
# expression statements.

Thomas

PS Use GDC withe the dstar patches to catch those statements
February 21, 2005
On Sun, 20 Feb 2005 17:55:13 -0800, Unknown W. Brackets <unknown@simplemachines.org> wrote:
> I would think that most compilers would be able to tell this:
>
> while (true)
> {
> }
>
> Is the same as this:
>
> while (true)
> 	continue;

Maybe, but why should they have to?
Having several ways to achieve the same thing is generally a bad idea.

> So a "noop" wouldn't be required... and, in most cases, when you do:
>
> if (true)
> {
> }
>
> Well, I can only imagine that being useful for an else/else if simlpification, which is ugly imho and hopefully is optimized out anyway.
>
> I can't really think of a case where a "noop" would be required...

That's because you're thinking of this idea in different terms.

I'm not trying to suggest noop is 'required' in order to achieve some program logic, what I'm suggesting is that it might improve readability and avoid bugs.

> and anyway, couldn't you do this:
>
> if (true)
> 	0;

I have no idea. It's beside the point I am trying to make.

Is using "noop" more obvious that the various connotations you've shown so far for telling other programmers that you intend for nothing to happen at that point in the code?

[For]
- If there is only 1 way, then once you learn that 1 way, it's obvious.
- It's unlikely you'll type "noop" by accident and if the other methods are made illegal then you cannot accidently type a no-op i.e.

for(s = bf; *s != '\0'; s++);  <- accidental semicolon here
   length++

[Against]
- One more keyword to learn.

Regan

> -[Unknown]
>
>
>> On Sun, 20 Feb 2005 17:07:59 -0800, Unknown W. Brackets  <unknown@simplemachines.org> wrote:
>>
>>> Yep, or, in the more common cases:
>>>
>>> foreach (char c; "")
>>>     continue;
>>>
>>> while (true)
>>>     continue;
>>>
>>> Which makes it a lot cleaner and more readable imho (but obviously  cannot be done for if.)
>>>
>>> -[Unknown]
>>   <snip rest of upside down reply>
>>  Or we could add a "noop" expression, to more exactly specify the  programmers intent.
>> eg.
>>  foreach(char c; "") noop;
>> while(true) noop;
>> if (true) noop;
>>  Regan

« First   ‹ Prev
1 2 3