Coding trick: Toggle code with comment switch

Some time ago I stumbled over a neat trick in programming languages which understand C++-like comment lines (single- and multi-lined comments). This allows toggling between two different blocks of code by just adding or removing a simple '/' character in the first line.

    /*  <<- Add/remove one '/' here to toggle active code block
    String mode = "release";
    String mode = "debug";

I found this somewhere on but couldn't locate the article containing this again. I found a reference to this here but I guess this trick is much, much older than this article.


Similar entries