Sometimes when you’re coding, you find yourself toggling a block of code on or off by commenting it. Most development environments make this pretty easy with a button or shortcut that will comment or uncomment a selected block.
However, it can be handy to know that there’s a way to achieve the same thing by setting up your block comments in such a way that they can be enabled or disabled by adding or removing a single “/”.
Here’s how it looks with the code commented out:
/*
thisIsCodeIWant.toToggle(onOff);
andMoreCodeHere();
//*/ |
You can uncomment the code block by adding a “/” at the start of the block comment like so:
//* thisIsCodeIWant.toToggle(onOff); andMoreCodeHere(); //*/ |
After I posted this, hbb reminded me of a related commenting trick. With the following set-up you can toggle between two code blocks by adding a “/”.
//* thisIsCodeBlock(1); moreCode(); /*/ thisIsCodeBlock(2); andMore(); //*/ |
Just remove the “/” at the beginning of the first block comment to swap code blocks.
/* thisIsCodeBlock(1); moreCode(); /*/ thisIsCodeBlock(2); andMore(); //*/ |
This is a pretty basic tip, but I’ve found that not all developers are aware of it, so I thought it couldn’t hurt to share it.
Thanks Grant! Nice handy tip π
Well, I didn’t know and it sure is useful so thanks for sharing π
I didn’t know that, I’ve setup shortcuts even in the FlashIDE just for that. Handy indeed π
Great tip π
Thank’s Grant, very useful π
It’s so handy~
I use the CMD+/ or CTRL+/ in eclipse (using Flash Builder plugin) to toggle // comments on each highlighted line. There’s also CMD+SHIFT+C or CTRL+SHIFT+C for MXML files to block comment MXML.
Yes. this tip can be used a switch of code segment like this
//*/
code segment 1
/*/
code segment 2
//*/
source link
http://ticore.blogspot.com/2008/03/actionscript-multiline-comment-tip.html
hbb – that’s another good one. Thanks for the reminder! I’ll update the post with it.
Too good.Cool tip and I am ready to implement,much needed at my work.
what i use is:
/**
something
/**/
when i need to uncomment i just add a /:
/**/
something
/**/
similar solution
I’ve used this combination for many years. It’s amazing!
Thank you, very useful info.
I go with the shortcuts Brandon posted.
This means that when code is uncommented, I don’t leave lines such as ‘//*’ and ‘//*/’ that where used for comments to be tidied up later, or hanging around for ever.
hahaha i love this kind of tricks! very handy indeed!
I use a slightly different technique.
/* */
something
/* */
another thing
/* */
when I need to comment just need to add 1 space:
/* * /
something commented
/* */
another thing
/* */
and it can be used to many blocks of code.. just requires adding/removing one space at each code block.
thanks for the post, truly a great tip!
had to chime in…
nothing beats flashdevelop when it comes to code commenting.
ctrl+c (toggle line comments).
ctrl+shift+c (toggle block comments).
being able to toggle on/off by just having the cursor in the commented block or on the line you wish to comment is just awesome.
A really nice blog !
Dekla
Doh, So obvious! Thanks for sharing….
Hi everybody! I want to join the community! What should I Do?
More generally toggle odd / even blocks extending this technique :
//*/
$a = 1;
/*/
$b = 1;
/*/
$c = 1;
/*/
$d = 1;
/*/
$e = 1;
/*/
$f = 1;
/*/
$g = 1;
/*/
$h = 1;
/*/