Every keystroke is a prisoner - a neat commenting trick
Date : 2008 02 28 Category : Tech & DevelopmentMy favourite kind of tutorial or trick are the ones that are very easy to do but make a lot of sense - you know the ones that make you slap your forehead and say "why didn't I do that before?".
Dirk Ginader blogged about a commenting trick (in German) that is one of these. He rightly claims that when you develop, you will comment and uncomment a lot as you optimise and test your code. This means either inserting lines with comment and deleting those lines, adding and deleting the /* */ by hand or using a shortcut of your editor of choice (I loved Homesite for ctrl+shift+m). In any case, it means highlighting several lines to comment in or out.
If you however use the following syntax then you only need to delete one slash to comment and uncomment a section:
PLAIN TEXT JAVASCRIPT:foo();
/*
bar();
baz.foo = 200;
return{
dolly:clone()
}
// */
The trick is the // before the closing */. With this you can just add another slash before the opening one and uncomment the block this way.
PLAIN TEXT JAVASCRIPT:foo();
//*
bar();
baz.foo = 200;
return{
dolly:clone()
}
// */
This works in many languages, alas not in CSS as there is no single line comment.