Is it possible to have nesting of comments




















Find centralized, trusted content and collaborate around the technologies you use most. Connect and share knowledge within a single location that is structured and easy to search. When you nest a comment, replace "--" with "- -". When you un-nest, reverse the procedure.

An HTML comment is not quite what many think it is. This is why comments like this one which we've all likely done one time or another are a bad idea:. Truth: I am too lazy to tell you how many comments are represented by the above tag pollution, but it's at least I got less lazy: This so-called "comment" actually consists of 10 comments, three words outside any comment i.

It's a real mess:. Of course, it's not quite that simple, due to differences in how each browser chooses to interpret the spec.

Within an SGML declaration, comments are delimited by double-dashes. Thus, the HTML comment. It is an SGML declaration that is empty except for a comment. Out of interest, here's a chunk of pure SGML that shows comments functioning as they were intended in SGML: this attribute list definition contains a comment on each line:.

If you're really stuck with some piece of HTML — pre-rendered at some uncontrollable source — which contains comments, and you need to make sure none of it is rendered on your page, you can always wrap it with a script tag like below, only thing is, you can't comment out script tags this way.

If you need to comment out script tags, you could use a textarea as wrapper instead, off course doing it this way, you can't comment out textarea tags. Use template tag. The fastest way to block all the comment and other html from showing up. It lets you toggle it on and off. Visual Studio e.

I think it isn't allowed, but as far as I know it works in most of the major browsers except in Firefox. So my challenge to you is this. Is there a way to make the nesting infinite within the UI? You mentioned Reddit, at the beginning of the video. Something like Reddit. Or if this was a to-do list app, listing one main to-do and then being able to list sub to-dos infinitely. What made this a little more difficult is the setup of having comments with a list of replies as well as replies with lists of replies.

This setup is however the setup that scales the best I believe ;. A second lesser problem with a 2-character comment delimiter is that an extra space between the two-character comment delimiter will cause the comment to be missed.

For example:. So is the above trying to do division or was an accidental space put after the slash and before the asterisk of a comment?

This problem will probably be caught be the compiler, or at least I have not been able to come up with an example where the compiler would not find it.

Where can comments be placed? Can comments go before or after the program? In most modern languages comments can go before or after the program. But in XML comments are not allowed before the first statement. In most languages a comment can go any place a space would occur except within a character string or within another comment. While the previous rule is a common description of where comments can go, it is not quite correct.

A comment cannot be placed where it would hide the start or end of a block comment. So were you smart enough to see what was wrong with the above comment? The last line has an end-of-line comment that hides the ending of the block comment.

I am sure you saw it. XHTML has similar potential problems. For example, XML comments cannot go within declarations, tags, or other comments. All of the following are illegal in XML:. There are several commenting errors in the above XML code. In the last four lines we have comments inside comments nested comments which is also not allowed.

Comments inside comments nested would often be useful and this topic is discussed next. One serious problem with multiple-line comments is forgetting to terminate a comment. What is incorrect with the above code? Go back and look at it again. If you missed the error this shows how easy that error is to miss.

This type of error, called a run-away comment , is a very difficult bug to locate! Comments that are stopped at the end of the line avoid this problem.

This problem is the primary reason people argue that multiple line comments are a bad option. Thus there is some debate whether multiple-line comments are a good or bad idea. Ada does not have multiple-line comments. Instead their comment starts with two dashes and terminate at the end of the line. I imagine they decided against having multiple-line comments to avoid the problem of run-away comments. There are several solutions to this problem of nested comments. Another method for avoiding the error of not terminating a comment is for the compiler to check for statement terminators the semicolon in comments and provide a warning.

Otherwise, we can allow nested comments, but the compiler can indicate any comments that do not nest properly, and warn about nested comments. Different languages use different approaches and each approach seems to have its own benefits and drawbacks.

So one may jump to the conclusion that nested comments should be outlawed. But there is another opinion. Besides that nested comments are useful, neat, and elegant, there is another good reason for wanting them. When we need to comment out statements that have comments:. If we do not allow and handle nested comments, the first comment will end with end of the second comment, and than the last line is like a dangling else, but now we have a dangling comment closing. If we allow nested comments, then everything works fine.

The solution of allowing nested comments would be similar to our approach of nested blocks and nested if-then-else statements. We match the closing comment symbol with the closest previous opening comment symbol.

The problem of nested comments is a large problem. During testing, debugging, or for early releases of software, we may need to comment out hundreds of line of code. We hope all these lines have many comments. Few modern languages handle this problem well. Some languages allow nested comments. REXX and Haskell have nested comments and they nest like any other structure needing nesting. Aug 16, Matt Busigin. Aug 17, Walter. Aug 17, Angus Graham.

Aug 17, Kent Sandvik. Aug 22, Erik Rounds. Aug 23, Walter. Aug 23, Rajiv Bhagwat. Aug 24, Dan Hursh. Aug 24, Russell Bornschlegel. Oct 29, Sean L. Aug 17, rogalsky. Aug 17, Sheldon Simms. Aug 17, Christophe de Dinechin. Aug 21, Walter. Mark Shackelford Permalink Reply. It won't work.



0コメント

  • 1000 / 1000