Preference for disabling large blocks of code?

Occasionally we disable large blocks of code in Octave C++ files. Is there a preference for how this is done? I see three current strategies

  1. C pre-processor commenting, #if 0 / #endif
  2. multi-line C-style commenting, /* ... */
  3. multiple, single-line C++ commenting // line1, // line2, ...

I generally prefer some form of #if / #endif.

In what cases is disabling large blocks of code better than just deleting? Is there an intent to restore it later?

That’s my question as well. Maybe it seemed at the time like it would be a good idea just to disable a block because it might need to be reversed. But we’ve had good version control for years. If I need to reverse a specific changeset I can just use hg backout -r REVISION. And I know that some of the #if 0 blocks have been in the code forever.

For reference, I used grep to find a list of #if 0 instances. There are 75 which is a meaningful number. List is attached.

The most interesting one is in the documentation file testfun.txi where we explicitly advocate #if 0 as one way of hiding BIST tests from a C++ compiler.

You can also create test scripts for built-in functions and your own C++
functions.  To do so, put a file with the bare function name (no .m
extension) in a directory in the load path and it will be discovered by
the @code{test} function.  Alternatively, you can embed tests directly in your
C++ code:

@example
@group
/*
%!test disp ("this is a test")
*/
@end group
@end example

@noindent
or

@example
@group
#if 0
%!test disp ("this is a test")
#endif
@end group
@end example

if0.list (3.3 KB)