Nested comments in MXML
Recently, while using Flex 2 Alpha 1, I found that I could not comment out a section of MXML that itself contained comments. As a developer, I'm used to quickly commenting out bits of code while debugging and Flex Builder even provides a handy shortcut for this: Source -> Block Comment.
Unfortunately, this feature currently has two shortcomings that make it a less-than-ideal solution.
Firstly, as I mentioned above, it cannot be used to comment out MXML that itself contains comments and, secondly, it cannot be used to comment out ActionScript code within mx:Script tags.
The second issue shouldn't be too hard to fix and even the first one can be avoided with a little workaround.
The first shortcoming is actually a limitation of XML: You can't nest XML comments.
The Block Comment feature currently places comment tags <!-- -->
around a selected bit of MXML. This works correctly unless the markup itself contains comments, in which case, the document ceases being valid XML. So, what's the workaround? Simple: You can use a script to comment out areas of MXML that contain comments.
So, instead of <!-- -->
, the Block Comment feature could wrap the selected text with the following tags:
<!-- MXML BLOCK COMMENT --> <mx:Script> <![CDATA[ /* <!-- Put anything here, including other XML comments --> */ ]]> </mx:Script>
Concise, well-written comments that clarify the intent of code is the mark of a good programmer. The importance of commenting not just your ActionScript code but your MXML increases with Flex 2, as more logic becomes contained in the MXML via data binding, validation, states, etc. And, as more and more comments are placed in the MXML, the current Block Comment feature will break more often and for a larger number of users when commenting out blocks of code while debugging.
If, however, the suggestions herein are implemented, the Block Comment feature should become indispensible and widely used. Here's to that! :)
Comments
by dbk111 on 2008-01-26 19:02:52
by Joseph on 2007-11-07 18:51:03
by shaz GM lovely on 2010-04-27 11:18:43
by Eric on 2010-04-30 19:56:42
by Sandcarving on 2011-02-15 23:00:05
by yeah on 2011-03-04 16:08:21
by Maria on 2012-09-26 05:29:55