digitalmars.D - (Non) Nesting block comments
- Michiel Helvensteijn (14/14) Jul 20 2009 D has the old C style block comments that start with /* and end with the
- Bill Baxter (7/21) Jul 20 2009 I tend to use /* */ for writing multi-line comments. and /+ +/ for
- Michiel Helvensteijn (7/11) Jul 20 2009 But do you not still start every line of comment with * or such? I know ...
- Bill Baxter (16/25) Jul 20 2009 his
- bearophile (6/10) Jul 20 2009 C compatibility is an important goal of D, so you can't put it aside.
- Michiel Helvensteijn (6/12) Jul 20 2009 I can understand that. It would break compatibility:
- Robert Fraser (5/21) Jul 20 2009 /* is good when commenting out code moving upwards. You put one */ at
- Marianne Gagnon (5/24) Jul 20 2009 In C++, I use comments for 2 purposes :
- Leandro Lucarella (20/28) Jul 20 2009 /++
- Robert Jacques (7/22) Jul 20 2009 Well /* */ are excellent for toggling code sections. I tend to use
- Michiel Helvensteijn (7/12) Jul 21 2009 Why? I believe that /++/ works exactly like /**/ in that regard. Doesn't...
- Michel Fortin (16/29) Jul 21 2009 I'm pretty sure he meant comment out a signle line at the top, not
- Michiel Helvensteijn (5/14) Jul 21 2009 Aha. Interesting construction. I like it. No, you couldn't do that with
- Robert Fraser (3/33) Jul 21 2009 Wow, you just blew my mind. I wish they taught this sort of stuff in
- yigal chripun (4/40) Jul 22 2009 IMHO, this is an ugly trick. it's less readable IMO and it just saves a ...
- Michiel Helvensteijn (15/21) Jul 22 2009 The point is not the amount of keystrokes. The point is that such a
- Michel Fortin (14/19) Jul 21 2009 I'd say that this is a much better way for activating/deactivating code
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
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 HelvensteijnI 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
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
On Mon, Jul 20, 2009 at 2:46 PM, Michiel Helvensteijn<m.helvensteijn.remove gmail.com> wrote:Bill Baxter wrote:hisI tend to use /* */ for writing multi-line comments.But do you not still start every line of comment with * or such? I know t=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.--bbI 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.
Jul 20 2009
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
bearophile wrote:Of course. It was mostly theoretical. It may be generally interesting.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.)I can understand that. It would break compatibility: /* /* */ (here be code in C, comment in D) -- Michiel Helvensteijn
Jul 20 2009
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
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
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
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
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
On 2009-07-21 05:31:13 -0400, Michiel Helvensteijn <m.helvensteijn.remove gmail.com> said:Robert Jacques wrote: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/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 / //+/
Jul 21 2009
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
Michel Fortin wrote:On 2009-07-21 05:31:13 -0400, Michiel Helvensteijn <m.helvensteijn.remove gmail.com> said:Wow, you just blew my mind. I wish they taught this sort of stuff in programming 101.Robert Jacques wrote: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.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 / //+/
Jul 21 2009
Michel Fortin Wrote:On 2009-07-21 05:31:13 -0400, Michiel Helvensteijn <m.helvensteijn.remove gmail.com> said: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+/ -- yigalRobert Jacques wrote: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/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 / //+/
Jul 22 2009
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
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