I’ve stumbled on some uses of if False/if True
in the stack, which apparently were debugging statements that got left in on commit, or blocks of code that were intentionally left in for future reference. Here’s an example:
https://github.com/lsst/afw/blob/master/tests/mask.py#L102
There are 116 instances of if False:
in the stack, and 23 if True:
s. Quite a few are in tests. There’s also a couple dozen #if 0
and #if 1
in the .h and .cc files, many of which appear in the SWIG wrapped files. Apparently those were put in by SWIG, though its not clear?
I was told that this was often used because the LSST coding standards do not allow commented out code. I couldn’t find a reference to that in the coding standards: is there an explicit statement about this? To my mind, if there is a good reason to not just delete the line, commenting it out with an attached comment saying why, e.g. “# this should be faster, but it gives the wrong result”, seems much better than wrapping it in “if False”: the commented line doesn’t disrupt one’s flow when reading whereas you have to parse the conditional, it adds an indent level, and editors don’t give you color syntax hints about which branch gets executed.
Similarly, “#if 0” in C++: why not just comment out that block? Some editors (e.g. SublimeText) will color the now-ignored block, but not all editors do. I know /* */
can break if there’s another /* */
block in the middle, but this should not be used for big blocks of code anyway.
Is there a global #define LSST_DEBUG that one can use in C++, and/or something similar in python? That at least would make it slightly more clear about whether a given block of code exists just for debugging purposes.
If the coding standards already say something about this, please point me to them, otherwise I think the standards probably should include some discussion of this.