Most of you might comment out code like this:
...
main();
// alternateMain();
...
But this isn't a really efficient way to comment. If you need to toggle that comment, you need to delete/add at least two characters. And also, sometimes you are trying two different things, and need to comment one and uncomment another. Things get complex really quick
Here, I'll show you some efficient ways to comment out stuff. This is based on JavaScript, but should work for other languages like CSS, C, etc. (And you probably can adapt it to other languages).
Toggleable comment
For commenting a block of code and making it easier to uncomment, you can do this:
/*/
experimental();
/**/
If you want to uncomment, just add a *
to the first line:
/**/
experimental();
/**/
You can't "nest" comments here, so one trick you can use is to put the comment text in the last comment:
No:
/*/ never(); /* Some explanatory text here blabla */ experiment2(); /**/
Yes:
/*/ gonna(); experiment2(); /* Some explanatory text here blabla */
Nice?
We can pretty easily extend this. Check this out:
/*/
experimental();
/*/
stable();
/**/
Now, the first block is commented, but the second isn't. Just add a *
:
/**/
experimental();
/*/
stable();
/**/
Aaand it was toggled and we are running experimental()
!
You can even put them inline:
use(/**/ stable /*/ experimental /**/);
If you want to comment out both, just remove the *
in the middle:
/*/
experimental1();
//
experimental2();
/**/
And if you want to uncomment both, add a *
in the middle:
/**/
experimental1();
/**/
experimental2();
/**/
Awesome right?
Now, this looks like the end of it, but there's more!
Check this out:
/**/
experimental1();
/**/
experimental2();
/**/
give();
/**/
If you want to comment out a line, just remove one ending /
from the top of that line:
/**/
experimental1();
/**
experimental2();
/**/
you();
/**/
Also works for multiple lines!
/**/
experimental1();
/**
experimental2();
/**
up();
/**/
You can pretty much infinitely extend that. And of course, don't let these comments past the 'just testing stuff' phase...