nested comments

Jonathan M Davis jmdavisProg at gmx.com
Mon May 30 19:46:35 PDT 2011


On 2011-05-30 18:52, Ary Manzana wrote:
> On 5/31/11 7:58 AM, Nick Sabalausky wrote:
> > "bearophile"<bearophileHUGS at lycos.com>  wrote in message
> > news:is1dj6$ihb$1 at digitalmars.com...
> > 
> >> Jesse Phillips:
> >>> The purpose is commenting out code, but note that there is also
> >>> version(none) { } which is never compiled in.
> >> 
> >> version(none) {} is probably the official way to comment out code.
> >> And if you use a versioning system to keep your code, then commenting
> >> out code is not a so wise thing to do.
> > 
> > Why not? I've never heard of a VCS that went around stripping out all
> > comments.
> 
> The question is: why comment and commit code that you can already find
> in the commit history? Then you end up with huge files with things like:
> 
> /*
>   * Maybe we will use this in a future, this is not working right now
>   ...
>   ...
>   ...
>   */
> 
> and the code becomes a mess.
> 
> So I agree with bearophile here.

I'd say that most people would consider it to be bad ediquette to commit 
commented out code to a repository in most cases. The VCS does allow you to 
get at old code if you need to. So, commenting out code is generally for 
development purposes only.

However, there _are_ occasionally cases where it makes sense to comment out 
code and check it in that way - such as when a compiler bug makes a unit test 
fail, and it doesn't make sense to be running the test until the compiler bug 
is fixed. std.array has a few functions which were added as commented out, 
because they can't actually be added until some of its other functions have 
been deprecated and removed (since they share the same name but different 
behavior - e.g. insert is being replaced by insertInPlace, and the version of 
insert which doesn't insert in place can't be added to std.array until the 
original insert is gone). But it makes good sense for the implementations to 
be there, ready to be put into service as soon the old functions are gone, so 
they're there but comment out.  In most cases, however, you shouldn't be 
checking in commented code. It just makes for messier code and most people 
consider it to be bad etiquette.

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list