Home arrow static arrow Java Programming [Archive] - reason why you cannot nest multiline comments?
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - reason why you cannot nest multiline comments?
This topic has 18 replies on 2 pages.    1 | 2 | Next »

Posts:2,562
Registered: 6/7/02
reason why you cannot nest multiline comments?  
Jul 21, 2004 10:58 AM



 
hi,

just out of interest..

is there any reason why nesting multi-line comments doesn't work? I can understand its probably harder to parse but it would allow you to comment out two methods, and then the whole file without having to first uncomment the two methods you initially commented

i realize this is trivial in a way, but was just wondering if there was something that broke if you did allow this :)

thanks,
asjf
 

Posts:2,206
Registered: 8/15/02
Re: reason why you cannot nest multiline comments?  
Jul 21, 2004 11:18 AM (reply 1 of 18)



 
Not sure what you mean. I can use /* and */ for multi-line comments just fine. You just can't nest multi-line comments inside multi-line comments; i.e.
/*for (int i=0; i<10; i++) {    /* Loop over all the integration        the following will close the outer comment, not the inner    */    x = i+1;}*/ // This last does nothing since it is no longer part of the comment
 

Posts:24,036
Registered: 2/3/03
Re: reason why you cannot nest multiline comments?  
Jul 21, 2004 11:25 AM (reply 2 of 18)



 
The few IDEs I work with allow to comment out multiple lines by highlighting them and hitting a hotkey...
 

Posts:3,258
Registered: 00-08-28
Re: reason why you cannot nest multiline comments?  
Jul 21, 2004 11:31 AM (reply 3 of 18)



 
The few IDEs I work with allow to comment out multiple
lines by highlighting them and hitting a hotkey...

right. In WSAD/Eclipse you could select a piece of code
1) highlight
2) goto the context menu(click right mouse button)
3) >source>comment
 

Posts:24,036
Registered: 2/3/03
Re: reason why you cannot nest multiline comments?  
Jul 21, 2004 11:36 AM (reply 4 of 18)



 
The few IDEs I work with allow to comment out
multiple
lines by highlighting them and hitting a hotkey...

right. In WSAD/Eclipse you could select a piece of
code
1) highlight
2) goto the context menu(click right mouse button)
3) >source>comment

Or just Ctrl-/ in lieu of #2 and #3. Ctrl-\ removes the comments.
 

Posts:10,972
Registered: 10/23/03
Re: reason why you cannot nest multiline comments?  
Jul 21, 2004 11:44 AM (reply 5 of 18)



 
Why don't multiline comments nest? There's a hint in the JLS, where they call them traditional comments.
Comments don't nest in C and they were left the same way in Java.
 

Posts:3,258
Registered: 00-08-28
Re: reason why you cannot nest multiline comments?  
Jul 21, 2004 11:53 AM (reply 6 of 18)



 
Why don't multiline comments nest? There's a hint in
the JLS, where they call them traditional
comments.
Comments don't nest in C and they were left the same
way in Java.

well yes you could have nested comments this way

//	/**//	 * @param set//	 *///	private void setFiltAllowableProducts(ChangeAwareSet set)//	{////		this.filtAllowableProducts = set;////	}


But that s not what the OP is asking about.
 

Posts:37,103
Registered: 3/30/99
Re: reason why you cannot nest multiline comments?  
Jul 21, 2004 11:55 AM (reply 7 of 18)



 
Why don't multiline comments nest? There's a hint in
the JLS, where they call them traditional
comments.
Comments don't nest in C and they were left the same
way in Java.

Which begs the question...
 

Posts:3,055
Registered: 18/06/98
Re: reason why you cannot nest multiline comments?  
Jul 21, 2004 1:30 PM (reply 8 of 18)



 
Trying to use nested block comments in C remember my good old times using Pascal:


(* a comment (* inside another *) and another *)


- well, I've used the VM/360 and CDC Pascal compilers (I believe that the CDC Pascal compiler was written by someone at ETH, maybe the own Niklaus Wirth...), that used (* and *) for comments instead of the more modern "{" and "}" comment delimiters. ("{" and "}" for comment delimiters are almost "invisible" in listings, so I always use some extra character, like "{-- --}", to make them more visible.)

Some old C compilers silently accepted the nesting of "/*" comments; today they follow the standard.
 

Posts:474
Registered: 3/12/04
Re: reason why you cannot nest multiline comments?  
Jul 21, 2004 1:34 PM (reply 9 of 18)



 
edsonw plz can u help me ?
 

Posts:13,769
Registered: 00-11-29
Re: reason why you cannot nest multiline comments?  
Jul 21, 2004 1:48 PM (reply 10 of 18)



 
Not really an answer to the question but I've started using the recommended (by Sun) practice of using /* */ only for permanent comments and // only for commenting out code. I like it pretty well given the forementioned IDE shortcuts. It makes things that are 'commented out' stand out from things that are actually comments. I also almost always put the // at the very beginning of the line.
 

Posts:3,258
Registered: 00-08-28
Re: reason why you cannot nest multiline comments?  
Jul 21, 2004 1:50 PM (reply 11 of 18)



 
Not really an answer to the question but I've started
using the recommended (by Sun) practice of using /* */
only for permanent comments and // only for commenting
out code.

I couldnt agree more
 

Posts:2,909
Registered: 13.8.2003
Re: reason why you cannot nest multiline comments?  
Jul 22, 2004 2:11 AM (reply 12 of 18)



 
I couldnt agree more

I could if I tried really hard.
 

Posts:2,562
Registered: 6/7/02
Re: reason why you cannot nest multiline comments?  
Jul 22, 2004 2:49 AM (reply 13 of 18)



 
thanks for the explanations, this is actually more interesting than i originally thought :o)

Trying to use nested block comments in C remember my
good old times using Pascal:

so you could nest multiline comments in Pascal? wonder if they changed this for c#?
 

Posts:2,830
Registered: 9/1/03
Re: reason why you cannot nest multiline comments?  
Jul 22, 2004 3:25 AM (reply 14 of 18)



 
is there any reason why nesting multi-line comments
doesn't work? I can understand its probably harder to
parse but it would allow you to comment out two
methods, and then the whole file without having to
first uncomment the two methods you initially
commented

Could also lead to either confusing results or a much more complicated
parsing system of comments (event compilation errors in comments :D
who remembers when escape sequences crashed in comments ...)

Consider this code:
class NestProb {	/**	public void m(){		System.out.println("/*** How are you ?");	}	*/}
What happens here ?

And then consider if the string isn't compilable ... should the parser check it ?

Hmm.
 
This topic has 18 replies on 2 pages.    1 | 2 | Next »