Every keystroke is a prisoner - a neat commenting trick
Written by on February 28th, 2008 in Ajax News.
My 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:
/*
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.
//*
bar();
baz.foo = 200;
return{
dolly:clone()
}
// */
This works in many languages, alas not in CSS as there is no single line comment.
Update: in CSS you can just delete and add and remove an asterisk:
border:1px solid red;
/*/
background-color:blue;
/**/
margin:1em;
}
border:1px solid red;
/**/
background-color:blue;
/**/
margin:1em;
}
Source: Ajaxian
Original Article: http://feeds.feedburner.com/~r/ajaxian/~3/242603827/every-keystroke-is-a-prisoner-a-neat-commenting-trick