Most languages I’ve worked with don’t have support for recursive comments.
- Is there any reason why language designers would choose not to implement this?
- Is it deceptively complex?
- Would it have undesired results?
Example of a recursive comment:
/*
for (int j = 0; j <= SourceTexture.Height; j += SampleSize)
{
...
}
// Comment within comment below:
/*for (int i = 0; i < TextureColour.Length; i++)
{
...
}*/
sourceTexture.SetData<Color>(TextureColour);
*/
EDIT: I understand the argument of the answers so far (problems occur when you have comment tokens in strings). However, the reason for my confusion is that you have that problem now.
For example, i know the code below wouldn’t give the expected result.
/*
char *str = "/* string";
// Are we now 1 level inside a comment or 2 levels?
*/
printf("Hello world");
/*
char *str2 = "string */";
*/
But in my mind that’s no different to an unexpected result in the case below:
/*
CODE "*/";
*/
Which would also yield an unexpected/undesired result.
So, while it could be a problem for recursive comments, my argument as to why that’s not a reason not to do it, is that it is already a problem for non-recursive comments. As a programmer i know the compiler behaves like this and i work around it. I don’t think it’s much more effort to work around the same problem with recursive comments.
It makes the lexical analysis more difficult to implement.
IMHO, no, but this is subjective.
Hard to tell. You have already discovered that even normal block comments can make problems:
I know 2 languages that have nesting block comments: Haskell and Frege.