A Small Enhancement Idea

Jack Stouffer via Digitalmars-d digitalmars-d at puremagic.com
Wed Sep 2 09:28:10 PDT 2015


I wanted some second opinions on an idea I had for D before I 
made a bugzilla issue.

Currently in D, to have a statement run only in debug mode, you 
can mark it with the debug keyword. But, there is currently no 
way to mark a statement so that it only runs in release. So what 
I propose is a release statement like so:

debug {
     // only runs when -debug is given
}

release {
     // only runs when -release is given
}

Or, if adding a new keyword to the language is a no go, it could 
be done like so:

debug {
     // only runs when -debug is given
} else {
     // only runs when -release is given
}

I have run into a need for this twice in one day, both having to 
do with unit tests in phobos. For the first one, I needed a way 
to make sure that a function is @nogc in release. For the other, 
the function I was tested had different outputs for release and 
debug if the input was an empty range, and I had no way to test 
both cases.

I can think of several other use cases off the top of my head. 
One, If you have a GUI application that checks for a serial 
number on startup, there's no reason to do that check in a debug 
build. Or, if your making a game, there's no reason to do the 
opening logo crawl before the menu if your using debug mode.

A rebuttal to this might be to just use version and pass 
something in during compilation. The problem that I have is this 
is not a solution for the phobos code that I am working on. Also, 
I think the first example above is very clear code and follows 
the debug statement's precedent.


More information about the Digitalmars-d mailing list