version()

Peter Alexander peter.alexander.au at gmail.com
Mon Jan 16 05:11:55 PST 2012


== Quote from Jonathan M Davis (jmdavisProg at gmx.com)'s article
> On Monday, January 16, 2012 11:37:13 Marco Leise wrote:
> > I would like to write:
> >
> > void main() {
> >      version(!unittest) {
> >          run_the_program();
> >      }
> > }
> >
> > This is a case where the trait you check for is so specific that
checking
> > for the negation has a clear benefit. I agree with your opinion
on OS
> > versions, which are more like an enum, where you go through it
like a
> > switch-case.
> That's done easily enough:
> version(unittest) void main() {}
> else void main()
> {
>     //the program
> }
> As long as you only need to be able to say "this version" and "not
this
> version" rather than "this version", "that version", and "not some
other
> version," you're okay, since the else essentially functions as a !.
It just
> won't do it for more complicated chains of versions.
> - Jonathan M Davis

I know it's easy to workaround with else, but why require a
workaround at all? Should we ban the use of ! in normal if statements
as well because you can write:

if(cond) {}
else
{

}

!!??

The fact that workarounds are required for trivial cases is an
indication that the system is broken.


More information about the Digitalmars-d mailing list