www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Ambiguous comment syntax

reply Oliver Hoog <kingboscop nospam.gmail.com> writes:
Since one of D's goals is dropping the bad things from C/C++, I wonder 
why the ambiguous syntax for multi-line comments is still allowed:
---
	auto p = new int;
	*p = 10;
	auto j = 100/*p;    <- error
---
There is already the unambiguous /+...+/ syntax, so why not drop the 
/*...*/ syntax? Compatibility? Convenience? I think D should be more 
pragmatic.
What do you think?
Aug 08 2009
next sibling parent "Adam D. Ruppe" <destructionator gmail.com> writes:
On Sun, Aug 09, 2009 at 02:25:04AM +0200, Oliver Hoog wrote:
 There is already the unambiguous /+...+/ syntax, so why not drop the 
 /*...*/ syntax? Compatibility? Convenience?
Both.
 I think D should be more pragmatic.
Pragmatism includes sticking to established habits in humans. This is one of those habits. -- Adam D. Ruppe http://arsdnet.net
Aug 08 2009
prev sibling next sibling parent reply Rainer Deyke <rainerd eldwood.com> writes:
Oliver Hoog wrote:
 There is already the unambiguous /+...+/ syntax, so why not drop the
 /*...*/ syntax? Compatibility? Convenience? I think D should be more
 pragmatic.
 What do you think?
I don't think D needs two inline comment forms, but /+...+/ is no less ambiguous than /*...*/. Don't forget about the unary '+' operator: auto p = 1; auto j = 100/+p; (Also, "multi-line"? I only use /*...*/ for inline comments that end before the end of the line. I use multiple instances of '//' if I want a comment that extends beyond the end of a line.) -- Rainer Deyke - rainerd eldwood.com
Aug 08 2009
parent language_fan <foo bar.com.invalid> writes:
Sat, 08 Aug 2009 19:26:48 -0600, Rainer Deyke thusly wrote:

 
 I don't think D needs two inline comment forms, but /+...+/ is no less
 ambiguous than /*...*/.  Don't forget about the unary '+' operator:
We could also overload .. to define a vector dot product, and *** for cross product.
Aug 10 2009
prev sibling parent reply Daniel Keep <daniel.keep.lists gmail.com> writes:
Oliver Hoog wrote:
 Since one of D's goals is dropping the bad things from C/C++, I wonder
 why the ambiguous syntax for multi-line comments is still allowed:
 ---
     auto p = new int;
     *p = 10;
     auto j = 100/*p;    <- error
 ---
 There is already the unambiguous /+...+/ syntax, so why not drop the
 /*...*/ syntax? Compatibility? Convenience? I think D should be more
 pragmatic.
 What do you think?
It's not ambiguous. Tokens are matched with maximal munch meaning that /* is ALWAYS the opening of a multi-line comment.
Aug 08 2009
parent Stewart Gordon <smjg_1998 yahoo.com> writes:
Daniel Keep wrote:
<snip>
 It's not ambiguous.  Tokens are matched with maximal munch meaning that
 /* is ALWAYS the opening of a multi-line comment.
Actually, it isn't always maximal munch - for example, 2..3 tokenises as 2 .. 3 rather than 2. .3. But you're right about comment syntax. Stewart.
Aug 09 2009