Thread overview | |||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
January 23, 2004 [Style Guide] Nested Comments | ||||
---|---|---|---|---|
| ||||
According to the style guide nested comments should "comment out" trial code.
But current the compiler does not support this style well. This is because the lexical analysis treats comments on a "first come first serve" base. I.e. "/+" and "+/" can be included with no harm in "//" and "/*" comments as well as in strings.
Then, when commenting out this trial code, the included nested "/+" and "+/" suddenly come to life, forcing the need to include several "/+" at the begin of the trial code or several "+/" at the end of the trial code in order to have the block of code properly have commented out.
Example:
<code>
/+/+/+
/*
* comment "+/" ...
*
*/
statement; // comment "+/" ...
statement; // comment "/+" ...
printf(".../+...",...);
+/+/+/ </code>
In addition, when changing the relevant parts of the inner comments or strings the starts and endings of the nested comment must be changed accordingly.
Shouldn't the compiler neglect "/+" and "+/" in included comments and strings when processing nested comments?
So long.
--
Fight Spam! Join EuroCAUCE: http://www.euro.cauce.org/ 2EA56D6D4DC41ABA311615946D3248A1
|
January 23, 2004 Re: [Style Guide] Nested Comments | ||||
---|---|---|---|---|
| ||||
Posted in reply to Manfred Nowak | Manfred Nowak wrote: > According to the style guide nested comments should "comment out" trial code. > > But current the compiler does not support this style well. This is because the lexical analysis treats comments on a "first come first serve" base. I.e. "/+" and "+/" can be included with no harm in "//" and "/*" comments as well as in strings. > > Then, when commenting out this trial code, the included nested "/+" and "+/" suddenly come to life, forcing the need to include several "/+" at the begin of the trial code or several "+/" at the end of the trial code in order to have the block of code properly have commented out. > > Example: > <code> > /+/+/+ > > /* > * comment "+/" ... > * > */ > > statement; // comment "+/" ... statement; // comment "/+" ... > printf(".../+...",...); > > +/+/+/ </code> > > In addition, when changing the relevant parts of the inner comments or strings the starts and endings of the nested comment must be changed accordingly. > > Shouldn't the compiler neglect "/+" and "+/" in included comments and strings when processing nested comments? > > So long. I think I understand your point, but I don't view this is a commonly-occurring problem. I think you might be missing the purpose of nested comments. Nested comments are optional. No one will ever force you to use them. I've never been hindered by them. If you don't like them, you can use // and /* */ if they are too much trouble. On the other hand, I consider them to be a gift. In fact, nested commments is one of the reasons that I'm involved in D. They can be left in code permanently, but what I really like to use them for is temporary situations (where I want to leave code out and see what happens). I guess I haven't coded anything with code like this in it: printf("/+"); but I guess if I did I'd just use /* */ or // to comment it out. I might be annoyed for a second, but then I hope I'd just take a deep breath and work it out. It seems the way it works right now, once the compiler sees a /+ it goes into nested commment mode. All it's looking for is either another /+ to take it up another level or +/ to go down towards actual code. That's it. It's easier for Walter to write the compiler that way. It's easier for the rest of us to write tools for that way. (Not that I have any strong opinions on the matter...) -- Justin http://jcc_7.tripod.com/d/ |
January 23, 2004 Re: [Style Guide] Nested Comments | ||||
---|---|---|---|---|
| ||||
Posted in reply to J C Calvarese | While it was 23/1/04 4:00 am throughout the UK, J C Calvarese sprinkled little black dots on a white screen, and they fell thus: <snip> > I think I understand your point, but I don't view this is a commonly-occurring problem. I think you might be missing the purpose of nested comments. The point, surely, is so that you can comment out any block of code without worrying about comment delimiters already in it. To achieve this perfectly would mean continuing to check whether the comment delimiters are within strings or non-nesting comments in the commented out code. > Nested comments are optional. No one will ever force you to use them. I've never been hindered by them. If you don't like them, you can use // and /* */ if they are too much trouble. If /+ +/ are too much trouble, then you might as well just forget /* */ with respect to the OP's example. > On the other hand, I consider them to be a gift. In fact, nested commments is one of the reasons that I'm involved in D. They can be left in code permanently, but what I really like to use them for is temporary situations (where I want to leave code out and see what happens). I guess I haven't coded anything with code like this in it: > printf("/+"); <snip> I agree. Now the question is: is TextPad going to support nested comments soon? Just looking at the style guide, and the /+++++ ... +++++/ in the example, I suppose it could have been designed so that, if you have / followed by a number of +s at the beginning, you need the same number of +s followed by a / to end it. Maybe this is WUTB now.... Stewart. -- My e-mail is valid but not my primary mailbox, aside from its being the unfortunate victim of intensive mail-bombing at the moment. Please keep replies on the 'group where everyone may benefit. |
January 23, 2004 Re: [Style Guide] Nested Comments | ||||
---|---|---|---|---|
| ||||
Posted in reply to Stewart Gordon | Stewart, My textpad syntax file is old (DMD 0.65) and needs an update, but you can get it here: http://www.penguinblotter.com/d/d.syn It supports nested comments as I see it. Maybe you could show me an example of this syntax file not doing it correctly? BA Stewart Gordon wrote: > While it was 23/1/04 4:00 am throughout the UK, J C Calvarese sprinkled little black dots on a white screen, and they fell thus: > > <snip> > >> I think I understand your point, but I don't view this is a commonly-occurring problem. I think you might be missing the purpose of nested comments. > > > The point, surely, is so that you can comment out any block of code without worrying about comment delimiters already in it. To achieve this perfectly would mean continuing to check whether the comment delimiters are within strings or non-nesting comments in the commented out code. > >> Nested comments are optional. No one will ever force you to use them. I've never been hindered by them. If you don't like them, you can use // and /* */ if they are too much trouble. > > > If /+ +/ are too much trouble, then you might as well just forget /* */ with respect to the OP's example. > >> On the other hand, I consider them to be a gift. In fact, nested commments is one of the reasons that I'm involved in D. They can be left in code permanently, but what I really like to use them for is temporary situations (where I want to leave code out and see what happens). I guess I haven't coded anything with code like this in it: >> printf("/+"); > > <snip> > > I agree. Now the question is: is TextPad going to support nested comments soon? > > Just looking at the style guide, and the /+++++ ... +++++/ in the example, I suppose it could have been designed so that, if you have / followed by a number of +s at the beginning, you need the same number of +s followed by a / to end it. Maybe this is WUTB now.... > > Stewart. > |
January 23, 2004 Re: [Style Guide] Nested Comments | ||||
---|---|---|---|---|
| ||||
Posted in reply to Brad Anderson | While it was 23/1/04 3:57 pm throughout the UK, Brad Anderson sprinkled little black dots on a white screen, and they fell thus: > Stewart, > > My textpad syntax file is old (DMD 0.65) and needs an update, but you can get it here: > http://www.penguinblotter.com/d/d.syn It looks almost identical to mine, at least the Syntax section does apart from the exact order of the directives. > It supports nested comments as I see it. Maybe you could show me an example of this syntax file not doing it correctly? <snip top of upside-down reply> At the moment I can't see any directive indicating nested comments at all. But I'll take it home and try it over the weekend. BTW what version of TextPad are you using? Mine's 4.5.0, probably time to upgrade.... Stewart. -- My e-mail is valid but not my primary mailbox, aside from its being the unfortunate victim of intensive mail-bombing at the moment. Please keep replies on the 'group where everyone may benefit. |
January 23, 2004 Re: [Style Guide] Nested Comments | ||||
---|---|---|---|---|
| ||||
Posted in reply to Stewart Gordon | same - 4.5.0
in syntax:
CommentStart = /*
CommentEnd = */
CommentStartAlt = /+
CommentEndAlt = +/
maybe the order matters ...
BA
Stewart Gordon wrote:
> While it was 23/1/04 3:57 pm throughout the UK, Brad Anderson sprinkled little black dots on a white screen, and they fell thus:
>
>> Stewart,
>>
>> My textpad syntax file is old (DMD 0.65) and needs an update, but you can get it here:
>> http://www.penguinblotter.com/d/d.syn
>
>
> It looks almost identical to mine, at least the Syntax section does apart from the exact order of the directives.
>
>> It supports nested comments as I see it. Maybe you could show me an example of this syntax file not doing it correctly?
>
> <snip top of upside-down reply>
>
> At the moment I can't see any directive indicating nested comments at all. But I'll take it home and try it over the weekend. BTW what version of TextPad are you using? Mine's 4.5.0, probably time to upgrade....
>
> Stewart.
>
|
January 24, 2004 Re: [Style Guide] Nested Comments | ||||
---|---|---|---|---|
| ||||
Posted in reply to Stewart Gordon | Stewart Gordon wrote: > While it was 23/1/04 4:00 am throughout the UK, J C Calvarese sprinkled little black dots on a white screen, and they fell thus: > > <snip> > >> I think I understand your point, but I don't view this is a commonly-occurring problem. I think you might be missing the purpose of nested comments. > > > The point, surely, is so that you can comment out any block of code without worrying about comment delimiters already in it. To achieve this perfectly would mean continuing to check whether the comment delimiters are within strings or non-nesting comments in the commented out code. > >> Nested comments are optional. No one will ever force you to use them. I've never been hindered by them. If you don't like them, you can use // and /* */ if they are too much trouble. > > > If /+ +/ are too much trouble, then you might as well just forget /* */ with respect to the OP's example. Then use //. My supposition is that no matter how we design this system, someone can come up with an example that makes it look flawed. So we could get in an endless loop of adding complexity to the compiler until no one wants to implement the compiler or any parsing tools. An unimplemented compiler is an unpopular one. > >> On the other hand, I consider them to be a gift. In fact, nested commments is one of the reasons that I'm involved in D. They can be left in code permanently, but what I really like to use them for is temporary situations (where I want to leave code out and see what happens). I guess I haven't coded anything with code like this in it: >> printf("/+"); > > <snip> > > I agree. Now the question is: is TextPad going to support nested comments soon? Actually, I'm not aware are any syntax editor that treats nested comments as nested comments instead of as block comments. (Please let know if you've found one.) Currently, if I mess up the nested comments so that it doesn't run, I use d2html (available at my website) to see where it went wrong. Apparently, Programmers Notepad allows the use of a parser plug-in, so that might be the easiest way to bring comprehensive nested comment support to an editor. But it would probably still involve some effort and I'm pretty lazy. > > Just looking at the style guide, and the /+++++ ... +++++/ in the example, I suppose it could have been designed so that, if you have / followed by a number of +s at the beginning, you need the same number of +s followed by a / to end it. Maybe this is WUTB now.... > > Stewart. That's a pretty neat idea, but I'm still going to vote for the status quo since I'm lazy and don't want to add any complexity d2html if I don't have to. -- Justin http://jcc_7.tripod.com/d/ |
January 24, 2004 Re: [Style Guide] Nested Comments | ||||
---|---|---|---|---|
| ||||
Posted in reply to J C Calvarese | > Stewart Gordon wrote:
>
> > While it was 23/1/04 4:00 am throughout the UK, J C Calvarese sprinkled little black dots on a white screen, and they fell thus:
Stewart, is it possible for you to round-robin a set of "amusing" phrases, as the lit dot sprinkles one is getting well old?
Smarmy Sid
|
January 24, 2004 Re: [Style Guide] Nested Comments | ||||
---|---|---|---|---|
| ||||
Posted in reply to Manfred Nowak | "Manfred Nowak" <svv1999@hotmail.com> wrote in message news:bupvr8$14eo$1@digitaldaemon.com... > Shouldn't the compiler neglect "/+" and "+/" in included comments and strings when processing nested comments? The behavior works as intended, although the manual could say it better. |
January 24, 2004 Re: [Style Guide] Nested Comments | ||||
---|---|---|---|---|
| ||||
Posted in reply to J C Calvarese | "J C Calvarese" <jcc7@cox.net> wrote in message news:busfmc$2832$1@digitaldaemon.com... > My supposition is that no matter how we design this system, someone can come up with an example that makes it look flawed. Yes, it's like stepping on a bubble in a carpet. It flattens out under your shoe, but pops up in another annoying location. The current semantics of /+ +/ enable it to be used to comment out arbitrary text as long as it doesn't contain /+ or +/, not just D code. > So we could get in > an endless loop of adding complexity to the compiler until no one wants > to implement the compiler or any parsing tools. I prefer something straightforward and easy to understand, even if perhaps that makes it suboptimal for some situations. I was once introduced via email to someone who was described as the world's leading expert on the C preprocessor. I don't want to create a language that opens a niche for the creation of a world's leading expert on some aspect of it <g>. That said, I obviously need to fix up the explanation of it in the manual a bit. > An unimplemented compiler is an unpopular one. Yes. |
Copyright © 1999-2021 by the D Language Foundation