D - [Style Guide] Nested Comments
- Manfred Nowak (31/31) Jan 22 2004 According to the style guide nested comments should "comment out" trial
- J C Calvarese (25/62) Jan 22 2004 I think I understand your point, but I don't view this is a
- Stewart Gordon (22/34) Jan 23 2004 While it was 23/1/04 4:00 am throughout the UK, J C Calvarese sprinkled
- Brad Anderson (8/51) Jan 23 2004 Stewart,
- Stewart Gordon (14/21) Jan 23 2004 It looks almost identical to mine, at least the Syntax section does
- Brad Anderson (9/34) Jan 23 2004 same - 4.5.0
- J C Calvarese (22/64) Jan 23 2004 Then use //.
- Matthew (3/6) Jan 23 2004 Stewart, is it possible for you to round-robin a set of "amusing" phrase...
- Walter (14/20) Jan 24 2004 Yes, it's like stepping on a bubble in a carpet. It flattens out under y...
- Manfred Nowak (11/13) Jan 24 2004 Don't get me wrong.
- Manfred Nowak (19/25) Jan 24 2004 vim does. I am working on a syntax file for vim. But there is a bug in
- marcus (7/20) Jan 24 2004 I made a Vim syntax file for Lua 5 (it comes with vim 6.2), where long s...
- Manfred Nowak (11/14) Jan 24 2004 [...]
- Georg Wrede (5/8) Jan 25 2004 You could always define [*[, [**[ and [***[, etc, as separate
- Ilya Minkov (12/38) Jan 24 2004 I find the situation stupid. I think it has to be classified as a bug.
- Walter (3/5) Jan 24 2004 The behavior works as intended, although the manual could say it better.
- Manfred Nowak (6/10) Jan 24 2004 Of course, that was only a proposal.
- Ilya Minkov (3/10) Jan 24 2004 It's counterintuitive. In all other languages all comment tokens within
- Walter (3/13) Jan 25 2004 That's not correct for C.
-
Carlos Santander B.
(9/9)
Jan 25 2004
"J Anderson"
wrote in message - J C Calvarese (20/31) Jan 25 2004 I sure hope a person doesn't to be an expert in C, C++, Java, and all
- Manfred Nowak (5/8) Jan 26 2004 However, your example comments in the comments-part are wrong. /*- and
- J C Calvarese (9/18) Jan 28 2004 You're right. My example was misleading. Since you brought this to my
- Manfred Nowak (15/16) Jan 28 2004 [...]
- J Anderson (11/24) Jan 29 2004 Personally I don't subscribe to this theory. When your commenting out
- Lewis (11/44) Jan 29 2004 if i might just interject my newbie $.02 here.. It is my opinion that a ...
- J Anderson (4/14) Jan 26 2004 I must have been tired. Whoops.
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
Jan 22 2004
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/
Jan 22 2004
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.
Jan 23 2004
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.
Jan 23 2004
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.synIt 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.
Jan 23 2004
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.synIt 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.
Jan 23 2004
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>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.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.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.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.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/
Jan 23 2004
Stewart Gordon wrote: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 SidWhile 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:
Jan 23 2004
"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.
Jan 24 2004
Walter wrote: [...]Don't get me wrong. The message subject contains "[Style Guide]". I wouldn't have posted it, when the style guide wouldn't contain the proposal of commenting out comments and strings. Nested comments are a beautiful idea by itself. So long. -- Fight Spam! Join EuroCAUCE: http://www.euro.cauce.org/ 2EA56D6D4DC41ABA311615946D3248A1An unimplemented compiler is an unpopular one.Yes.
Jan 24 2004
J C Calvarese wrote: [..]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.)vim does. I am working on a syntax file for vim. But there is a bug in vim, so that multiple endings must be separated by spaces. Thats how I invented the example. [...]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.If d2html is properly designed, then it should be neglectible work, as in vim. The declaration for the nestable comment is: | syn region CommentSlashPlus start="/+" end="+/" | contains= CommentSlashPlus Adding the other comments and strings would change it to | syn region CommentSlashPlus start="/+" end="+/" | contains= Comment, String Do you really think, that this is a complex task? So long. -- Fight Spam! Join EuroCAUCE: http://www.euro.cauce.org/ 2EA56D6D4DC41ABA311615946D3248A1
Jan 24 2004
In article <butv4d$1j5n$1 digitaldaemon.com>, Manfred Nowak says...vim does. I am working on a syntax file for vim. But there is a bug in vim, so that multiple endings must be separated by spaces. Thats how I invented the example. If d2html is properly designed, then it should be neglectible work, as in vim. The declaration for the nestable comment is: | syn region CommentSlashPlus start="/+" end="+/" | contains= CommentSlashPlus Adding the other comments and strings would change it to | syn region CommentSlashPlus start="/+" end="+/" | contains= Comment, String Do you really think, that this is a complex task? So long.I made a Vim syntax file for Lua 5 (it comes with vim 6.2), where long strings are delimited by [[ bla bla ]] and they nest. Long comments are --[[ bla bla ]] and they can have nested [[ bla bla ]]'s too. Now Lua authors are thinking of making delimiters like this [***[ bla bla ]***] (same number of *'s). Do you know if it's implementable in Vim? It's been a somewhat long time since i read Vim docs about syntax highlighting...
Jan 24 2004
marcus wrote: [...]Now Lua authors are thinking of making delimiters like this [***[ bla bla ]***] (same number of *'s). Do you know if it's implementable in Vim?[...] It is easy. Have a look at the docs with `:help ext-match'. Something like: | syn region C start="\[\z(\*\+\)\[" end="\]\z1\]" contains=C,... should do the work. So long. -- Fight Spam! Join EuroCAUCE: http://www.euro.cauce.org/ 2EA56D6D4DC41ABA311615946D3248A1
Jan 24 2004
In article <buue60$2abf$1 digitaldaemon.com>, marcus says...Now Lua authors are thinking of making delimiters like this [***[ bla bla ]***] (same number of *'s). Do you know if it's implementable in Vim? It's been a somewhat long time since i read Vim docs about syntax highlighting...You could always define [*[, [**[ and [***[, etc, as separate comment types. Of course, this wouldn't work with an arbitrary number of stars, only what you've explicitly defined. I think it would take much thinking to get this work for all possible numbers of stars.
Jan 25 2004
J C Calvarese wrote:I find the situation stupid. I think it has to be classified as a bug. With */, strings and line comments are also left out, so they should with +/.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("/+");If i recall correctly, in CREdit, when entering a syntax definition, you may specify that a comment be a nesting comment. Generally, i don't believe that multi-language editors don't support nesting comments, since Borland Pascal's neat {} comments nest.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.Hmmm... Maybe it's time to extend SciTE lexer. ;)NO WAY! The excess +s are an artistic mean to give value to comments and have to simply be ignored! ;) -eyeJust 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....
Jan 24 2004
"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.
Jan 24 2004
Walter schrieb:Of course, that was only a proposal. So long. -- Fight Spam! Join EuroCAUCE: http://www.euro.cauce.org/ 2EA56D6D4DC41ABA311615946D3248A1Shouldn'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.
Jan 24 2004
Walter wrote:"Manfred Nowak" <svv1999 hotmail.com> wrote in message news:bupvr8$14eo$1 digitaldaemon.com...It's counterintuitive. In all other languages all comment tokens within comments and strings are ignored, including /* */ in C.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.
Jan 24 2004
"Ilya Minkov" <minkov cs.tum.edu> wrote in message news:buu141$1lr4$2 digitaldaemon.com...Walter wrote:That's not correct for C."Manfred Nowak" <svv1999 hotmail.com> wrote in message news:bupvr8$14eo$1 digitaldaemon.com...It's counterintuitive. In all other languages all comment tokens within comments and strings are ignored, including /* */ in C.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.
Jan 25 2004
"J Anderson" <REMOVEanderson badmama.com.au> wrote in message news:bv17ej$eim$1 digitaldaemon.com... | Yeah, C doesn't even have /* */. | | -- | -Anderson: http://badmama.com.au/~anderson/ Wrong there: /* */ is the only way to comment C code. ----------------------- Carlos Santander Bernal
Jan 25 2004
Carlos Santander B. wrote:"J Anderson" <REMOVEanderson badmama.com.au> wrote in message news:bv17ej$eim$1 digitaldaemon.com... | Yeah, C doesn't even have /* */. | | -- | -Anderson: http://badmama.com.au/~anderson/ Wrong there: /* */ is the only way to comment C code. ----------------------- Carlos Santander BernalI sure hope a person doesn't to be an expert in C, C++, Java, and all varieties of Pascal (ANSI, Turbo, & Delphi) in order to discuss things around here. I was thinking that /* */ and // were fair game for commenting in C, C++, and Java. I guess not. (Maybe it depends on how compliant the compiler is.) I didn't realize until it was brought up the other day that Turbo Pascal allows { } to be nested. (ANSI Pascal apparently doesn't, but who follows that standard anyway?) I personally like the way commenting occurs in D. I'm not aware of another language that is so flexible that there are three distinct types of commenting. And with all of the contract-by-design goodies we shouldn't need as many comments, right? I learned how fancy comments worked in D from playing around with the compiler, and made up some examples of how it works in some more complicated cases (http://jcc_7.tripod.com/d/tutor/). -- Justin http://jcc_7.tripod.com/d/
Jan 25 2004
J C Calvarese schrieb: [...]I learned how fancy comments worked in D from playing around with the compiler, and made up some examples of how it works in some more complicated cases (http://jcc_7.tripod.com/d/tutor/).However, your example comments in the comments-part are wrong. /*- and //-comments do not nest, they are broken. So long.
Jan 26 2004
Manfred Nowak wrote:J C Calvarese schrieb: [...]You're right. My example was misleading. Since you brought this to my attention, I tried to make it more clear. I think this might be something that is difficult to teach, so hopefully people can make use of my example as a place to start until I can figure out how to explain it better.more complicated cases (http://jcc_7.tripod.com/d/tutor/).However, your example comments in the comments-part are wrong. /*- and //-comments do not nest, they are broken.So long.-- Justin http://jcc_7.tripod.com/d/
Jan 28 2004
J C Calvarese wrote: [...]I think this might be something that is difficult to teach[...] Because it is said, that it is easy to implement, it should be also be easy to teach: do not mix the different sorts of comments, hold them separated. Use comments for commenting, not for commenting out code. If trial code is supposed to be put out of work, then use version(trialcode){ ... }; In the rare circumstances, when `version(trialcode)' does not work, the use `/+'-comments with extreme care, beware of `/+' and `+/' in included strings, `/*'- and `//'-comments. The Style guide should be changed accordingly. So long.
Jan 28 2004
Manfred Nowak wrote:J C Calvarese wrote: [...]Personally I don't subscribe to this theory. When your commenting out code to debug something often it's only going to be commented out short term (ie 60 seconds, a few days). It's not a good idea to waste time putting in version(trialcode) { } when your only going to delete that anyway - waste of time. Most readers will know what you mean when you comment out a block of code. I due version state for debugging and profiling code however. But debugging code stays in the code much like unittests. -- -Anderson: http://badmama.com.au/~anderson/I think this might be something that is difficult to teach[...] Use comments for commenting, not for commenting out code. If trial code is supposed to be put out of work, then use version(trialcode){ ... };
Jan 29 2004
J Anderson wrote:Manfred Nowak wrote:if i might just interject my newbie $.02 here.. It is my opinion that a comment should be done in one way only, this avoids confusion and is easy to teach to anyone. // <comment> EOL simple, yet managable :) It seems to me as if alot of this other stuff is added to make it easier for people using notepad type editors to code with. I feel it should be an IDE's job for selecting and commenting a block of code. If someone wishes to use a simpler editor they should have to just deal with it, the way it is. Hardcore is supposed to be hard isnt it ;)J C Calvarese wrote: [...]Personally I don't subscribe to this theory. When your commenting out code to debug something often it's only going to be commented out short term (ie 60 seconds, a few days). It's not a good idea to waste time putting in version(trialcode) { } when your only going to delete that anyway - waste of time. Most readers will know what you mean when you comment out a block of code. I due version state for debugging and profiling code however. But debugging code stays in the code much like unittests.I think this might be something that is difficult to teach[...] Use comments for commenting, not for commenting out code. If trial code is supposed to be put out of work, then use version(trialcode){ ... };
Jan 29 2004
Carlos Santander B. wrote:"J Anderson" <REMOVEanderson badmama.com.au> wrote in message news:bv17ej$eim$1 digitaldaemon.com... | Yeah, C doesn't even have /* */. | | -- | -Anderson: http://badmama.com.au/~anderson/ Wrong there: /* */ is the only way to comment C code. ----------------------- Carlos Santander BernalI must have been tired. Whoops. -- -Anderson: http://badmama.com.au/~anderson/
Jan 26 2004