- HubPages»
- Technology»
- Computers & Software»
- Computer Science & Programming
How to comment out / restore your code faster
Introduction
Sometimes for the sake of testing / debugging, we'd comment out a portion of code temporarily, like this:
#include <iostream> using namespace std; int main() { int a = 1, b = 2, c = 6, d = 12; /* d = b + c; c = b * d; a = a + b; */ cout << a + c; return 0; }
After changing something, we may need to restore these code. Then we need to comment it out again... Keep comment out / restore the same code is indeed annoying. Actually, this can be done faster by using a small tip.
The Faster Way
1. When commenting out a portion of code, write the comment in this way:
#include <iostream> using namespace std; int main() { int a = 1, b = 2, c = 6, d = 12; /** d = b + c; c = b * d; a = a + b; /**/ cout << a + c; return 0; }
2. If you need to cancel that comment temporarily, just type a "/" at line 5 and it'll works:
#include <iostream> using namespace std; int main() { int a = 1, b = 2, c = 6, d = 12; /**/ d = b + c; c = b * d; a = a + b; /**/ cout << a + c; return 0; }
Summary
That's it, simple but useful in many cases. This works for C++, PHP, CSS, JavaScript and more.