nested comments
Jonathan M Davis
jmdavisProg at gmx.com
Tue May 31 18:11:49 PDT 2011
On 2011-05-31 18:03, Nick Sabalausky wrote:
> "Steven Schveighoffer" <schveiguy at yahoo.com> wrote in message
> news:op.vwcxmwfgeav7ka at localhost.localdomain...
>
> > 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.
>
> I prefer comments even for longer term. That way, it always gets
> highlighted as "THIS CODE IS NOT ACTIVE" and doesn't end up confusing me.
I honestly don't get the point of version(none). Sure, you get syntactic
analysis, but what good is that really? The code is still subject to bit-rot.
You're still going to have to make sure that it's valid if and when you enable
it again. Comments do just as good a job. All you lose is syntactic analysis
and syntactic highlighting. And I don't see much point in either for totally
inactive code.
- Jonathan M Davis
More information about the Digitalmars-d-learn
mailing list