www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - (Non) Nesting block comments

reply Michiel Helvensteijn <m.helvensteijn.remove gmail.com> writes:
D has the old C style block comments that start with /* and end with the
first possible */. But it also has nesting block comments, starting with /+
and ending with the *matching* +/.

The nesting block comments were a great idea, since they can be used
to 'comment out' any block of code, even if other block comments are
already present.

I was wondering, though. C++ compatibility aside, is there an actual use
case for the C style block comments anymore? Has anyone here written some
code lately where they thought: "I really need a comment here containing /+
or +/ without the matching delimiter! Thank <deity> for C style comments!"

(Yes, this is bikeshed stuff, and I don't really care. I like programming
language syntax discussions. Sometimes they are low barrier discussions.)

-- 
Michiel Helvensteijn
Jul 20 2009
next sibling parent reply Bill Baxter <wbaxter gmail.com> writes:
On Mon, Jul 20, 2009 at 1:53 PM, Michiel
Helvensteijn<m.helvensteijn.remove gmail.com> wrote:
 D has the old C style block comments that start with /* and end with the
 first possible */. But it also has nesting block comments, starting with /+
 and ending with the *matching* +/.

 The nesting block comments were a great idea, since they can be used
 to 'comment out' any block of code, even if other block comments are
 already present.

 I was wondering, though. C++ compatibility aside, is there an actual use
 case for the C style block comments anymore? Has anyone here written some
 code lately where they thought: "I really need a comment here containing /+
 or +/ without the matching delimiter! Thank <deity> for C style comments!"

 (Yes, this is bikeshed stuff, and I don't really care. I like programming
 language syntax discussions. Sometimes they are low barrier discussions.)

 --
 Michiel Helvensteijn
I tend to use /* */ for writing multi-line comments. and /+ +/ for temporarily zapping blocks of code. I like having that distinction, but I wouldn't fight very hard to preserve it if there was some good reason to kill /**/. But so far I don't think there is such a reason. --bb
Jul 20 2009
parent reply Michiel Helvensteijn <m.helvensteijn.remove gmail.com> writes:
Bill Baxter wrote:

 I tend to use /* */ for writing multi-line comments.
But do you not still start every line of comment with * or such? I know this is a matter of personal style, but I figured: might as well use // for multi-line comments.
 I like having that distinction,
 but I wouldn't fight very hard to preserve it if there was some good
 reason to kill /**/.  But so far I don't think there is such a reason.
No. There is no reason, other than simplification of the language. -- Michiel Helvensteijn
Jul 20 2009
parent Bill Baxter <wbaxter gmail.com> writes:
On Mon, Jul 20, 2009 at 2:46 PM, Michiel
Helvensteijn<m.helvensteijn.remove gmail.com> wrote:
 Bill Baxter wrote:

 I tend to use /* */ for writing multi-line comments.
But do you not still start every line of comment with * or such? I know t=
his
 is a matter of personal style, but I figured: might as well use // for
 multi-line comments.
For short doc comments, yes, I usually prefix each line with *. Ddoc and other systems don't handle multi-line /// doc comments as you might expect, so it's better to use /** for doc comments that are multiline. For non-doc comments explaining code internally I'll use // for short ones, but if it's over 4 or 5 lines I'll use /* */ without a * prefixing each line because it gets to be too annoying keeping all those ducks lined up, and it doesn't really help readability any. With /+ +/ and /* */ I think emacs-mode uses different colors. I can't recall though. If it doesn't it should. :-) So that makes (or would make) the difference between dead code and comments that I want to keep stand out more with the way I do things.
 I like having that distinction,
 but I wouldn't fight very hard to preserve it if there was some good
 reason to kill /**/. =A0But so far I don't think there is such a reason.
No. There is no reason, other than simplification of the language.
--bb
Jul 20 2009
prev sibling next sibling parent reply bearophile <bearophileHUGS lycos.com> writes:
Michiel Helvensteijn:
 I was wondering, though. C++ compatibility aside, is there an actual use
 case for the C style block comments anymore?
C compatibility is an important goal of D, so you can't put it aside. (Time ago I have suggested the opposite, to make the /* */ nestable and remove /+ +/, but this idea was not appreciated by D devs.)
 (Yes, this is bikeshed stuff, and I don't really care. I like programming
 language syntax discussions. Sometimes they are low barrier discussions.)
:-) Bye, bearophile
Jul 20 2009
parent Michiel Helvensteijn <m.helvensteijn.remove gmail.com> writes:
bearophile wrote:

 I was wondering, though. C++ compatibility aside, is there an actual use
 case for the C style block comments anymore?
C compatibility is an important goal of D, so you can't put it aside.
Of course. It was mostly theoretical. It may be generally interesting.
 (Time ago I have suggested the opposite, to make the /* */ nestable and
 remove /+ +/, but this idea was not appreciated by D devs.)
I can understand that. It would break compatibility: /* /* */ (here be code in C, comment in D) -- Michiel Helvensteijn
Jul 20 2009
prev sibling next sibling parent Robert Fraser <fraserofthenight gmail.com> writes:
Michiel Helvensteijn wrote:
 D has the old C style block comments that start with /* and end with the
 first possible */. But it also has nesting block comments, starting with /+
 and ending with the *matching* +/.
 
 The nesting block comments were a great idea, since they can be used
 to 'comment out' any block of code, even if other block comments are
 already present.
 
 I was wondering, though. C++ compatibility aside, is there an actual use
 case for the C style block comments anymore? Has anyone here written some
 code lately where they thought: "I really need a comment here containing /+
 or +/ without the matching delimiter! Thank <deity> for C style comments!"
 
 (Yes, this is bikeshed stuff, and I don't really care. I like programming
 language syntax discussions. Sometimes they are low barrier discussions.)
 
/* is good when commenting out code moving upwards. You put one */ at the bottom and add /*s to comment out more and more code until it works... Okay, that's a really bad use case, I might've done it twice in my life.
Jul 20 2009
prev sibling next sibling parent reply Marianne Gagnon <auria.mg gmail.com> writes:
In C++, I use comments for 2 purposes :

1) Add documentation
2) Disable code (also with #if 0 ... #endif)

Since those two actions are logically very different, I believe it's nice that
they're separate.

Why I *would* propose, however, is to get rid of /**  ... */, and say that /*
... */ is always for documentation.

 D has the old C style block comments that start with /* and end with the
 first possible */. But it also has nesting block comments, starting with /+
 and ending with the *matching* +/.
 
 The nesting block comments were a great idea, since they can be used
 to 'comment out' any block of code, even if other block comments are
 already present.
 
 I was wondering, though. C++ compatibility aside, is there an actual use
 case for the C style block comments anymore? Has anyone here written some
 code lately where they thought: "I really need a comment here containing /+
 or +/ without the matching delimiter! Thank <deity> for C style comments!"
 
 (Yes, this is bikeshed stuff, and I don't really care. I like programming
 language syntax discussions. Sometimes they are low barrier discussions.)
 
 -- 
 Michiel Helvensteijn
 
Jul 20 2009
parent Leandro Lucarella <llucax gmail.com> writes:
Marianne Gagnon, el 20 de julio a las 21:31 me escribiste:
 In C++, I use comments for 2 purposes :
 
 1) Add documentation
 2) Disable code (also with #if 0 ... #endif)
 
 Since those two actions are logically very different, I believe it's nice that
they're separate.
 
 Why I *would* propose, however, is to get rid of /**  ... */, and say that /*
... */ is always for documentation.
/++ + /++ +/ are good for documentation when you have code examples. + + Examples: + --------------------------- + /* A example function */ + int example() { + /+ some other comment +/ + return 1; + } + --------------------------- +/ -- Leandro Lucarella (luca) | Blog colectivo: http://www.mazziblog.com.ar/blog/ ---------------------------------------------------------------------------- GPG Key: 5F5A8D05 (F8CD F9A7 BF00 5431 4145 104C 949E BFB6 5F5A 8D05) ---------------------------------------------------------------------------- Y vos, me dijiste que soy, un abismo de silencio. SerĂ¡, porque vos no escuchas, que yo grito por dentro.
Jul 20 2009
prev sibling parent reply "Robert Jacques" <sandford jhu.edu> writes:
On Mon, 20 Jul 2009 16:53:11 -0400, Michiel Helvensteijn  
<m.helvensteijn.remove gmail.com> wrote:

 D has the old C style block comments that start with /* and end with the
 first possible */. But it also has nesting block comments, starting with  
 /+
 and ending with the *matching* +/.

 The nesting block comments were a great idea, since they can be used
 to 'comment out' any block of code, even if other block comments are
 already present.

 I was wondering, though. C++ compatibility aside, is there an actual use
 case for the C style block comments anymore? Has anyone here written some
 code lately where they thought: "I really need a comment here containing  
 /+
 or +/ without the matching delimiter! Thank <deity> for C style  
 comments!"

 (Yes, this is bikeshed stuff, and I don't really care. I like programming
 language syntax discussions. Sometimes they are low barrier discussions.)
Well /* */ are excellent for toggling code sections. I tend to use constructs such as // */ or //* or /*/ which allows me to turn on of off blocks with often a single key stroke. Using /+ +/ means I have to Add /++/ and remove /++/ each time I want to activate or deactivate a code block.
Jul 20 2009
next sibling parent reply Michiel Helvensteijn <m.helvensteijn.remove gmail.com> writes:
Robert Jacques wrote:

 Well /* */ are excellent for toggling code sections. I tend to use
 constructs such as // */ or  //* or /*/ which allows me to turn on of off
 blocks with often a single key stroke. Using /+ +/ means I have to Add
 /++/ and remove /++/ each time I want to activate or deactivate a code
 block.
Why? I believe that /++/ works exactly like /**/ in that regard. Doesn't it? //+ code that can be turned off by removing the first / //+/ -- Michiel Helvensteijn
Jul 21 2009
parent reply Michel Fortin <michel.fortin michelf.com> writes:
On 2009-07-21 05:31:13 -0400, Michiel Helvensteijn 
<m.helvensteijn.remove gmail.com> said:

 Robert Jacques wrote:
 
 Well /* */ are excellent for toggling code sections. I tend to use
 constructs such as // */ or  //* or /*/ which allows me to turn on of off
 blocks with often a single key stroke. Using /+ +/ means I have to Add
 /++/ and remove /++/ each time I want to activate or deactivate a code
 block.
Why? I believe that /++/ works exactly like /**/ in that regard. Doesn't it? //+ code that can be turned off by removing the first / //+/
I'm pretty sure he meant comment out a signle line at the top, not both, like this: /* A /*/ B /**/ With this, you compile B while A is in a comment. Add "/" at the start of the first line and you compile code A while B is now in commented out. -- Michel Fortin michel.fortin michelf.com http://michelf.com/
Jul 21 2009
next sibling parent Michiel Helvensteijn <m.helvensteijn.remove gmail.com> writes:
Michel Fortin wrote:

 /*
 A
 /*/
 B
 /**/
 
 With this, you compile B while A is in a comment. Add "/" at the start
 of the first line and you compile code A while B is now in commented
 out.
Aha. Interesting construction. I like it. No, you couldn't do that with nesting comments. I do wonder how often it comes up. -- Michiel Helvensteijn
Jul 21 2009
prev sibling next sibling parent Robert Fraser <fraserofthenight gmail.com> writes:
Michel Fortin wrote:
 On 2009-07-21 05:31:13 -0400, Michiel Helvensteijn 
 <m.helvensteijn.remove gmail.com> said:
 
 Robert Jacques wrote:

 Well /* */ are excellent for toggling code sections. I tend to use
 constructs such as // */ or  //* or /*/ which allows me to turn on of 
 off
 blocks with often a single key stroke. Using /+ +/ means I have to Add
 /++/ and remove /++/ each time I want to activate or deactivate a code
 block.
Why? I believe that /++/ works exactly like /**/ in that regard. Doesn't it? //+ code that can be turned off by removing the first / //+/
I'm pretty sure he meant comment out a signle line at the top, not both, like this: /* A /*/ B /**/ With this, you compile B while A is in a comment. Add "/" at the start of the first line and you compile code A while B is now in commented out.
Wow, you just blew my mind. I wish they taught this sort of stuff in programming 101.
Jul 21 2009
prev sibling parent reply yigal chripun <yigal100 gmail.com> writes:
Michel Fortin Wrote:

 On 2009-07-21 05:31:13 -0400, Michiel Helvensteijn 
 <m.helvensteijn.remove gmail.com> said:
 
 Robert Jacques wrote:
 
 Well /* */ are excellent for toggling code sections. I tend to use
 constructs such as // */ or  //* or /*/ which allows me to turn on of off
 blocks with often a single key stroke. Using /+ +/ means I have to Add
 /++/ and remove /++/ each time I want to activate or deactivate a code
 block.
Why? I believe that /++/ works exactly like /**/ in that regard. Doesn't it? //+ code that can be turned off by removing the first / //+/
I'm pretty sure he meant comment out a signle line at the top, not both, like this: /* A /*/ B /**/ With this, you compile B while A is in a comment. Add "/" at the start of the first line and you compile code A while B is now in commented out. -- Michel Fortin michel.fortin michelf.com http://michelf.com/
IMHO, this is an ugly trick. it's less readable IMO and it just saves a cuple keystrokes. readability is more important than that. more over, this is completely unneeded (unless you program in notepad) since even the simplest of the (programmer) text editors has a shortcut to comment/uncomment a block of code. For instance, in Eclipse it's Ctrl+Shift+/ -- yigal
Jul 22 2009
parent Michiel Helvensteijn <m.helvensteijn.remove gmail.com> writes:
yigal chripun wrote:

 IMHO, this is an ugly trick. it's less readable IMO and it just saves a
 cuple keystrokes. readability is more important than that. more over, this
 is completely unneeded (unless you program in notepad) since even the
 simplest of the (programmer) text editors has a shortcut to
 comment/uncomment a block of code. For instance, in Eclipse it's
 Ctrl+Shift+/
The point is not the amount of keystrokes. The point is that such a construction is automatic documentation of the fact that either the one or the other piece of code should be activated by the programmer (probably for debugging). Of course, you can pretty it up a little: //*/////////// A /*//////////// B //*/////////// But if you make this a convention in a project, every programmer will immediately understand. The fact that it takes only one keystroke to make the change is what gives the constructions its affordance. -- Michiel Helvensteijn
Jul 22 2009
prev sibling parent Michel Fortin <michel.fortin michelf.com> writes:
On 2009-07-20 23:51:42 -0400, "Robert Jacques" <sandford jhu.edu> said:

 Well /* */ are excellent for toggling code sections. I tend to use  
 constructs such as // */ or  //* or /*/ which allows me to turn on of 
 off  blocks with often a single key stroke. Using /+ +/ means I have to 
 Add  /++/ and remove /++/ each time I want to activate or deactivate a 
 code  block.
I'd say that this is a much better way for activating/deactivating code by from a single point in your file: version = NewStuff; // comment this out to do old stuff instead. version (NewStuff) { ... } else { ... } -- Michel Fortin michel.fortin michelf.com http://michelf.com/
Jul 21 2009