Duncan Booth wrote:
> Want to comment out a block of code in C++? The only (nearly) reliable way 
> is to insert single-line comments down the block. You can't use a block 
> comment if there are any other block comments inside the code you want to 
> block out.

As Roel said, #if 0 is the standard way.  It abuses the preprocessor and 
doesn't show up in syntax highlighting, but other than that works very 
well.  Honestly though, /* and */ should have nested properly since day 1. 
  Adding it wouldn't even break existing code.

> The danger of block comments is that if you forget to close the comment
> you can accidentally comment out a large part of your code. 

No, unclosed comments should raise a syntax error.  Would you accept an 
unclosed string literal?

> Doc strings will usually work as an alternative, especially since you
> have a choice of two flavours of triple quoted strings, so if you use
> one for docstrings the other is always free for your temporary block
> comments.

That's a fair point, if a bit of a kludge.  90% there is good enough in 
practice.

> This pig gets much more annoyed having to maintain code which has large 
> chunks of unneeded commented out code left over from some other programmer, 
> or which has completely messed up indentation.

Sure they can be abused.  So can a thousand other language features.  My 
point is you can't teach good coding through syntax, and trying to causes 
more problems than it solves.

I would argue the current system is in fact slightly worse, because people 
will comment out code chunks anyway (either lots of #s or triple-quotes) 
and are less likely to remove them when it's more work.  But either way, 
social pressure is infinitely more effective at cleaning up code than 
comment syntax.
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to