Z
Z
Zakharov Alexander2011-10-20 10:46:11
Source
Zakharov Alexander, 2011-10-20 10:46:11

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:
06663400.jpg
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:
1f4e49d3.jpg
3. When we want to uncomment the code, we put one fraction before the opening comment:
e15d88f7.jpg
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

6 answer(s)
P
Pavel Nazarov, 2011-10-20
@smbd

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 :)

D
DraculaDIS, 2011-10-20
@DraculaDIS

Sometimes I use this:

/**/
first algorithm
/*/
second algorithm
/*/

We remove * in the first line and the code is swapped

K
Konstantin Vlasov, 2011-10-20
@CaptainFlint

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.

R
red1ynx, 2011-10-20
@red1ynx

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.

A
Alexey, 2011-10-20
@alexxxst

I've been using this "trick" for 5 years already :)

A
Anatoly, 2011-10-20
@taliban


if( true )
{
    // код который надо коментировать переодически
}

The advantages of the approach are at least in code folding. If not needed, it can be folded into one line so that it does not loom.
There is one significant drawback in multi-line comments, so I try to use them less often:

some good code
/*
// some bad code
*/
some good code
/*
some bad code
*/
some good code

Now imagine, let's say that I need to comment out all this for a while, let's say for a test =) One multiline will not work, you need to comment on each "good" code separately

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question