Jump to page: 1 2
Thread overview
A Small Enhancement Idea
Sep 02, 2015
Jack Stouffer
Sep 02, 2015
H. S. Teoh
Sep 03, 2015
Timon Gehr
Sep 02, 2015
ponce
Sep 02, 2015
ponce
Sep 02, 2015
Jack Stouffer
Sep 02, 2015
Gary Willoughby
Sep 02, 2015
jmh530
Sep 02, 2015
Jack Stouffer
Sep 03, 2015
Xinok
Sep 04, 2015
Jonathan M Davis
Sep 03, 2015
Timon Gehr
Sep 04, 2015
Jonathan M Davis
Sep 04, 2015
Timon Gehr
September 02, 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.
September 02, 2015
On Wed, Sep 02, 2015 at 04:28:10PM +0000, Jack Stouffer via Digitalmars-d wrote:
> 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
> }

	debug {
		...
	}
	version(release)
	{
		...
	}


T

-- 
Don't throw out the baby with the bathwater. Use your hands...
September 02, 2015
On Wednesday, 2 September 2015 at 16:28:12 UTC, Jack Stouffer wrote:
> 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:
>

-release and -debug are decorrelated. Your program can have both switch or none of them.

September 02, 2015
On Wednesday, 2 September 2015 at 16:40:04 UTC, ponce wrote:
> On Wednesday, 2 September 2015 at 16:28:12 UTC, Jack Stouffer wrote:
>> 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:
>>
>
> -release and -debug are decorrelated. Your program can have both switch or none of them.

And here is the answer to your next question: so what does -release do exactly?

http://p0nce.github.io/d-idioms/#So-what-does--release-do,-exactly?
September 02, 2015
On Wednesday, 2 September 2015 at 16:40:04 UTC, ponce wrote:
> On Wednesday, 2 September 2015 at 16:28:12 UTC, Jack Stouffer wrote:
>> 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:
>>
>
> -release and -debug are decorrelated. Your program can have both switch or none of them.

I know. That doesn't somehow invalidate this idea.
September 02, 2015
On Wednesday, 2 September 2015 at 17:03:18 UTC, Jack Stouffer wrote:
> On Wednesday, 2 September 2015 at 16:40:04 UTC, ponce wrote:
>> On Wednesday, 2 September 2015 at 16:28:12 UTC, Jack Stouffer wrote:
>>> 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:
>>>
>>
>> -release and -debug are decorrelated. Your program can have both switch or none of them.
>
> I know. That doesn't somehow invalidate this idea.

H. S. Teoh's answer does.
September 02, 2015
On Wednesday, 2 September 2015 at 17:14:27 UTC, Gary Willoughby wrote:
> On Wednesday, 2 September 2015 at 17:03:18 UTC, Jack Stouffer wrote:
>> On Wednesday, 2 September 2015 at 16:40:04 UTC, ponce wrote:
>>> On Wednesday, 2 September 2015 at 16:28:12 UTC, Jack Stouffer wrote:
>>>> 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:
>>>>
>>>
>>> -release and -debug are decorrelated. Your program can have both switch or none of them.
>>
>> I know. That doesn't somehow invalidate this idea.
>
> H. S. Teoh's answer does.

I wasn't familiar with version(release). Would you need to compile with -version=release then?
September 02, 2015
On Wednesday, 2 September 2015 at 19:15:08 UTC, jmh530 wrote:
> I wasn't familiar with version(release). Would you need to compile with -version=release then?

No, it seems to work with just the -release flag.

The Python programmer in me hates the inconsistency between these two, but it's fine.
September 03, 2015
On Wednesday, 2 September 2015 at 19:34:53 UTC, Jack Stouffer wrote:
> On Wednesday, 2 September 2015 at 19:15:08 UTC, jmh530 wrote:
>> I wasn't familiar with version(release). Would you need to compile with -version=release then?
>
> No, it seems to work with just the -release flag.
>
> The Python programmer in me hates the inconsistency between these two, but it's fine.

I think it's for the better. The trouble with including keywords in the language is that it encourages their use. For example, there was once a suggestion to add a "namespace" keyword to the D language simply for the sake of linking with C++. There was a huge backlash because of the reason I stated before. I think the same philosophy applies here; we shouldn't add a "release" keyword because it would encourage it's use.

But why not encourage it? Because debug builds are for testing and, well, debugging your code. However, if there is "release-only" segments of code, then these are excluded from debug builds and so don't receive the same extensive testing and error checking as all other code. On the other hand, there are those corner cases when you actually need this which are adequately covered by the "version(release)" statement.

In summary, from a software engineering perspective, this is a bad idea in general and should be avoided wherever possible.
September 03, 2015
On 09/02/2015 06:32 PM, H. S. Teoh via Digitalmars-d wrote:
> On Wed, Sep 02, 2015 at 04:28:10PM +0000, Jack Stouffer via Digitalmars-d wrote:
>> 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
>> }
>
> 	debug {
> 		...
> 	}
> 	version(release)
> 	{
> 		...
> 	}
>
>
> T
>

Tested with DMD 2.068.0. This does not work.
« First   ‹ Prev
1 2