nested comments

Steven Schveighoffer schveiguy at yahoo.com
Tue May 31 11:00:22 PDT 2011


On Mon, 30 May 2011 20:43:18 -0400, bearophile <bearophileHUGS at lycos.com>  
wrote:

> 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.

I would add that there is a huge difference between version(none) and  
commenting -- version(none) code must still parse, whereas commenting out  
code is more flexible.

For example:

for(int i = 0; i < 100; i++)
    if(x == i)
    {
      writeln("found x")
      if(y == i)
         writeln("x and y are the same!");
    }


if you want to just comment out the if(x == i) line, using version(none)  
is not going to work well.

I would say that commenting out to test things is acceptable, but  
version(none) should be used when code is to be turned off long-term.

-Steve


More information about the Digitalmars-d-learn mailing list