October 21, 2014 debug = x overrides command line | ||||
---|---|---|---|---|
| ||||
Currently, if you write something like this: debug = x; It's like you passed -debug=x on the command line. However, this seems quite scary. It means that you are debugging ALL THE TIME, with any debug(x) statements. Does this make sense? Note that debug disables pure checking, which can be dangerous. I'm kind of uneasy that if I don't pass any debug arguments to the compiler, it can still violate purity in the name of debugging with such statements. I would have expected debug = x to only be enabled when -debug is passed to the compiler. Does this make sense to anyone? Note, there is no way to simply enable the same thing as -debug does in code. -Steve |
October 21, 2014 Re: debug = x overrides command line | ||||
---|---|---|---|---|
| ||||
Posted in reply to Steven Schveighoffer | On Tuesday, 21 October 2014 at 15:45:55 UTC, Steven Schveighoffer wrote:
> Currently, if you write something like this:
>
> debug = x;
In code? Like this:
void main()
{
debug = x;
// now in debug mode even though not specified on the CLI?
}
If that's true, that's pretty scary. What if it's hidden in a module somewhere?
|
October 21, 2014 Re: debug = x overrides command line | ||||
---|---|---|---|---|
| ||||
Posted in reply to Gary Willoughby | On 10/21/14 12:02 PM, Gary Willoughby wrote: > On Tuesday, 21 October 2014 at 15:45:55 UTC, Steven Schveighoffer wrote: >> Currently, if you write something like this: >> >> debug = x; > > In code? Like this: > > void main() > { > debug = x; > > // now in debug mode even though not specified on the CLI? > } > Yes, but only for debug(x) statements. debug statements without a symbol aren't enabled. But for those statements, purity is jettisoned. e.g.: import std.stdio; int a; void foonotpure() { a = 5; writeln("yep, not pure");} debug = x; // note this is only allowed at module scope. void main() pure { debug(x) foonotpure(); } dmd -run foonotpure.d yep, not pure > If that's true, that's pretty scary. What if it's hidden in a module > somewhere? Yep, you can just turn off purity when it gets in the way. -Steve |
October 21, 2014 Re: debug = x overrides command line | ||||
---|---|---|---|---|
| ||||
Posted in reply to Steven Schveighoffer | On Tuesday, 21 October 2014 at 17:25:37 UTC, Steven Schveighoffer wrote:
> On 10/21/14 12:02 PM, Gary Willoughby wrote:
>> On Tuesday, 21 October 2014 at 15:45:55 UTC, Steven Schveighoffer wrote:
>>> Currently, if you write something like this:
>>>
>>> debug = x;
>>
>> In code? Like this:
>>
>> void main()
>> {
>> debug = x;
>>
>> // now in debug mode even though not specified on the CLI?
>> }
>>
>
> Yes, but only for debug(x) statements. debug statements without a symbol aren't enabled. But for those statements, purity is jettisoned. e.g.:
>
> import std.stdio;
> int a;
>
> void foonotpure() { a = 5; writeln("yep, not pure");}
>
> debug = x; // note this is only allowed at module scope.
> void main() pure
> {
> debug(x) foonotpure();
> }
>
> dmd -run foonotpure.d
> yep, not pure
>
>> If that's true, that's pretty scary. What if it's hidden in a module
>> somewhere?
>
> Yep, you can just turn off purity when it gets in the way.
>
> -Steve
Wow!
|
October 21, 2014 Re: debug = x overrides command line | ||||
---|---|---|---|---|
| ||||
Posted in reply to Steven Schveighoffer | On Tuesday, 21 October 2014 at 17:25:37 UTC, Steven Schveighoffer
wrote:
> Yep, you can just turn off purity when it gets in the way.
>
> -Steve
Please raise a ticket for this.
|
October 21, 2014 Re: debug = x overrides command line | ||||
---|---|---|---|---|
| ||||
Posted in reply to Gary Willoughby | On 10/21/2014 12:15 PM, Gary Willoughby wrote:
> On Tuesday, 21 October 2014 at 17:25:37 UTC, Steven Schveighoffer
> wrote:
>> Yep, you can just turn off purity when it gets in the way.
>>
>> -Steve
>
> Please raise a ticket for this.
That was done deliberately - it's a feature. It enables things like debugging printf's to be inserted into pure functions.
|
October 21, 2014 Re: debug = x overrides command line | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | On Tuesday, 21 October 2014 at 19:24:03 UTC, Walter Bright wrote:
> On 10/21/2014 12:15 PM, Gary Willoughby wrote:
>> On Tuesday, 21 October 2014 at 17:25:37 UTC, Steven Schveighoffer
>> wrote:
>>> Yep, you can just turn off purity when it gets in the way.
>>>
>>> -Steve
>>
>> Please raise a ticket for this.
>
> That was done deliberately - it's a feature. It enables things like debugging printf's to be inserted into pure functions.
Ah, where's the documentation for this?
|
October 21, 2014 Re: debug = x overrides command line | ||||
---|---|---|---|---|
| ||||
Posted in reply to Gary Willoughby | On Tuesday, 21 October 2014 at 19:51:34 UTC, Gary Willoughby wrote: > Ah, where's the documentation for this? http://dlang.org/function.html#pure-functions > As a concession to practicality, a pure function can: [...] > perform impure operations in statements that are in a ConditionalStatement controlled by a DebugCondition. |
October 21, 2014 Re: debug = x overrides command line | ||||
---|---|---|---|---|
| ||||
Posted in reply to anonymous | On Tuesday, 21 October 2014 at 19:58:40 UTC, anonymous wrote:
> On Tuesday, 21 October 2014 at 19:51:34 UTC, Gary Willoughby
> wrote:
>> Ah, where's the documentation for this?
>
> http://dlang.org/function.html#pure-functions
>
>> As a concession to practicality, a pure function can:
> [...]
>> perform impure operations in statements that are in a ConditionalStatement controlled by a DebugCondition.
Right, that's all well and good but where does it say that you can assign a value to the debug keyword (in code) and it executes as if you had specified debug on the command line?
|
October 21, 2014 Re: debug = x overrides command line | ||||
---|---|---|---|---|
| ||||
Posted in reply to Gary Willoughby | On Tuesday, 21 October 2014 at 20:57:03 UTC, Gary Willoughby wrote: > On Tuesday, 21 October 2014 at 19:58:40 UTC, anonymous wrote: >> On Tuesday, 21 October 2014 at 19:51:34 UTC, Gary Willoughby >> wrote: >>> Ah, where's the documentation for this? >> >> http://dlang.org/function.html#pure-functions >> >>> As a concession to practicality, a pure function can: >> [...] >>> perform impure operations in statements that are in a ConditionalStatement controlled by a DebugCondition. > > Right, that's all well and good but where does it say that you can assign a value to the debug keyword (in code) and it executes as if you had specified debug on the command line? Aha http://dlang.org/version.html#DebugCondition |
Copyright © 1999-2021 by the D Language Foundation