Last Updated: February 25, 2016
·
717
· kbickley

Toggle Comment

Whenever I want to test an alternative implementation of some code I sometimes would like to preserve the old code and quickly toggle between the new and old implementation for comparison. I came up with a slick way to toggle between code using comments.

Example:

//*
if (name->Length() > 0) //Old way
{
    DoStuff(name);
}
/*/
if (name != NULL && name->Length() > 0) //New way
{
    DoStuff(name);
}
//*/

To toggle between the two implementations you simply remove the first / from the first comment.