If you have two blocks of code that you are testing and need to switch back-and-forth between them, here's a commenting trick that works as a powerful code block toggling mechanism.
Say you have a variable called
foo
of type
string
and want to change between using initialized values and non-initialized values for quick testing or more likely, because your boss asked you to. Silly boss!
string foo = string.Empty;
foo += "bar";
Now, to toggle the section that is 'live', simply remove the first slash from the first line comment, as follows:
string foo = "initialized";
foo += "bar";
Obviously, for a simple string there are easier ways to do this, but this is sure handy for more complex object setup.
There you go! With one keystroke you totally own on switching between two blocks of code.
While #ifdef works in some scenarios this technique also works in non-compiled languages such as JavaScript.
Cheers!
For almost 30 years I have been working with computers, learning a myriad of languages and participating in various computing environments.
Though I have been mentoring other developers for the last decade, I have recently found a strong interest in writing and am learning to translate the fun of in-person teaching to something I can get into article form.
I enjoy following technology trends, new gadgets and trying to guess where innovation will lead us next (I'm kinda holding out for a robot-served utopia, but willing to submit to our future robot leaders).
I am a guy who is passionate about my faith, my family and a cure for Juvenile Diabetes (my son lives with this disease).