Answer the question
In order to leave comments, you need to log in
Source code tricks?
Gentlemen, I want to share a little trick from using multi-line comments (I write in JavaScript, but it is also suitable for C-like languages.
The task is simple. You need to comment / uncomment a piece of code with one “clever” movement! Accidentally discovered a method for myself:
1. We write some code:
2. We frame this code with multiline comment signs, but only before the closing sign of the multiline comment we write a single-line comment sign:
3. When we want to uncomment the code, we put one fraction before the opening comment:
It turns out that one fraction can open / close a large piece of text , and don't look for the end of the comment.It's important that there are no multi-line comments inside.In
this regard, the question is:
Who knows more tricks?
Answer the question
In order to leave comments, you need to log in
I suggest instead of tricks with the source code, take an IDE that can block comments. And almost all IDEs can do this, and even text editors, and even vim (moreover, it can “invert” comments, which is also useful under certain circumstances).
But the trick is good :)
Sometimes I use this:
/**/
first algorithm
/*/
second algorithm
/*/
When I write in Syah or pluses, I often wrap such blocks in #if 0 / #endif, for uncommenting I replace 0 with 1. It is convenient that other comments /* ... */ can be present inside the block, and in this case it is described in the post method won't work.
In addition, several times it was required to compare the behavior of two different implementations, the #if 0 / #else / #endif method allowed switching between them by replacing one character.
Using the combinations Ctrl-K Ctrl-C and Ctrl-K Ctrl-U in Visual Studio or Ctrl-/ in Eclipse is more convenient for me to comment on pieces.
if( true )
{
// код который надо коментировать переодически
}
some good code
/*
// some bad code
*/
some good code
/*
some bad code
*/
some good code
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question