Jump to page: 1 2
Thread overview
nesting comments?
Aug 16, 2001
Mark Shackelford
Aug 16, 2001
Walter
Aug 16, 2001
Matt Busigin
Aug 17, 2001
Walter
Aug 17, 2001
Angus Graham
Aug 17, 2001
Kent Sandvik
Aug 22, 2001
Erik Rounds
Aug 23, 2001
Walter
Aug 23, 2001
Rajiv Bhagwat
Aug 24, 2001
Dan Hursh
Aug 17, 2001
Walter
Oct 29, 2001
Sean L. Palmer
Aug 17, 2001
rogalsky
Aug 17, 2001
Sheldon Simms
Aug 21, 2001
Walter
August 16, 2001
Hi!

With neither nesting comments nor preprocessor #if 0 / #endif available, how would a D programmer comment out a large section of code that contains multiline /* */ comments? It won't work. This would force everyone to use // comments everywhere just to be able at some future point to comment out blocks of code.

Either make /* ... */ nest, or add another nesting comment type. You
know, the evil Modula (* ... *) kind. ;^)

Cheers!

--
Mark Shackelford

August 16, 2001
To comment out a large block of code:

    if (0)
    {
        ... block of code ...
    }

The code must be syntactically correct, but not semantically correct. -Walter

"Mark Shackelford" <mark@shackelford-family.org> wrote in message news:3B7C4DD2.8B5E9470@shackelford-family.org...
> Hi!
>
> With neither nesting comments nor preprocessor #if 0 / #endif available, how would a D programmer comment out a large section of code that contains multiline /* */ comments? It won't work. This would force everyone to use // comments everywhere just to be able at some future point to comment out blocks of code.
>
> Either make /* ... */ nest, or add another nesting comment type. You
> know, the evil Modula (* ... *) kind. ;^)
>
> Cheers!
>
> --
> Mark Shackelford
>


August 16, 2001
Walter wrote:
> To comment out a large block of code:
> 
>     if (0)
>     {
>         ... block of code ...
>     }
> 
> The code must be syntactically correct, but not semantically
> correct. -Walter

This is not good enough - what about commenting out functions?  Global declarations?

August 17, 2001
"Matt Busigin" <mbusigin@helios.spang.org.uk> wrote in message news:3B7C4B0D.1040504@helios.spang.org.uk...
> Walter wrote:
> > To comment out a large block of code:
> >
> >     if (0)
> >     {
> >         ... block of code ...
> >     }
> >
> > The code must be syntactically correct, but not semantically correct. -Walter
>
> This is not good enough - what about commenting out functions?  Global declarations?

To comment out a function, you can wrap its entire code body with if(0){}. The function will still be there, but there'll be no code in it. Otherwise, you can use the debug attribute to get rid of blocks of declarations.


August 17, 2001
"Walter" <walter@digitalmars.com> wrote in message news:9lhng3
>
> To comment out a function, you can wrap its entire code body with if(0){}. The function will still be there, but there'll be no code in it.
Otherwise,
> you can use the debug attribute to get rid of blocks of declarations.
>

So to comment out a section of code I would have to change three lines in every function.  That sucks!

I don't understand - a decent editor colours comments so there's no question of which parts are commented out.

I'm totally naive when it comes to compiler implementation, but I can't imagine how nested comments would complicate things on the implementation side.

So why not allow them?


Angus Graham


August 17, 2001
"Angus Graham" <agraham_d@agraham.ca> wrote in message news:9lhphi$bts$1@digitaldaemon.com...

> I'm totally naive when it comes to compiler implementation, but I can't imagine how nested comments would complicate things on the implementation side.

I've always had problems with nested comments, the 'if 0' trick works just fine, lack of nested comments would not be a big minus for me when shopping for a good language. --Kent



August 17, 2001
"Angus Graham" <agraham_d@agraham.ca> wrote in message news:9lhphi$bts$1@digitaldaemon.com...
> "Walter" <walter@digitalmars.com> wrote in message news:9lhng3
> >
> > To comment out a function, you can wrap its entire code body with
if(0){}.
> > The function will still be there, but there'll be no code in it.
> Otherwise,
> > you can use the debug attribute to get rid of blocks of declarations.
> >
>
> So to comment out a section of code I would have to change three lines in every function.  That sucks!
>
> I don't understand - a decent editor colours comments so there's no
question
> of which parts are commented out.
>
> I'm totally naive when it comes to compiler implementation, but I can't
> imagine how nested comments would complicate things on the implementation
> side.
> So why not allow them?
> Angus Graham

The problem with nested comments is that programmers don't expect them to be nested. BTW, there is nothing in D that prevents the C preprocessor from being run over it if you really miss it (or any other text macro processor)!


August 17, 2001
Im Artikel <9lhng3$a5d$1@digitaldaemon.com> schrieb "Walter" <walter@digitalmars.com>:

> "Matt Busigin" <mbusigin@helios.spang.org.uk> wrote in message news:3B7C4B0D.1040504@helios.spang.org.uk...
>> Walter wrote:
>> > To comment out a large block of code:
>> >
>> >     if (0)
>> >     {
>> >         ... block of code ...
>> >     }
>> >
>> > The code must be syntactically correct, but not semantically correct. -Walter
>>
>> This is not good enough - what about commenting out functions?  Global declarations?
> 
> To comment out a function, you can wrap its entire code body with if(0){}. The function will still be there, but there'll be no code in it. Otherwise, you can use the debug attribute to get rid of blocks of declarations.

maybe there should just be an ignore block...

class ABC
{
  int this ()
  {...}

ignore {
  int a1 ()
  {...}

  int a2 ()
  {...}
}

  int b1 ()
  {...}
}

-- 
Sheldon Simms / sheldon@semanticedge.com
August 17, 2001
Angus Graham wrote:

> I don't understand - a decent editor colours comments so there's no question of which parts are commented out.
a decent editor can comment out whole block with "//" ...

-- 
                                  \\|//
                                  (. .)
+-----------------------------oOOo-(_)-oOOo----------------------------+
I Dipl. Phys. Olaf Rogalsky                 Institut f. Theo. Physik I I
I Tel.: 09131 8528440                       Univ. Erlangen-Nuernberg   I
I Fax.: 09131 8528444                       Staudtstrasse 7 B3         I
I rogalsky@theorie1.physik.uni-erlangen.de  D-91058 Erlangen           I
+----------------------------------------------------------------------+
August 17, 2001

Walter wrote:

> To comment out a large block of code:
>
>     if (0)
>     {
>         ... block of code ...
>     }
>
> The code must be syntactically correct, but not semantically correct. -Walter

As a compiler implementor, this makes me jump through the roof. In english: WHAAAT???

Let me combine that with other language features. Since I can reference forward declarations, I can write:

    void foo()
    {
        if (check_stuff) { ... }
    }
    void bar()
    {
        if (check_stuff) { ... }
    }

    const int check_stuff = 0; // make it 1 to enable stuff checking

See where I'm going? Now you have to defer semantics of foo and bar until the first-level semantics of every possibly constant declaration in the file has been processes. That's going to be ugly.

And last, what is considered a constant declaration? Let me build a corner case:

    const int check_stuff = (int) &bar - (int) &foo > 1024;

Now, you have a recursive constant declaration, which impacts the size of the functions, and depends on it. Good luck processing that ;-)


By the way, what if I want to disable a declaration? To remove debugging fields in a struct?



Christophe

« First   ‹ Prev
1 2