Thread overview
add attributes to debug
Jul 24, 2016
Gorge Jingale
Jul 24, 2016
Ivan Kazmenko
Jul 24, 2016
Gorge Jingale
Jul 25, 2016
Adam D. Ruppe
Jul 25, 2016
Gorge Jingale
Jul 25, 2016
ag0aep6g
July 24, 2016
To allow for different debug versions without having to go full blown version().

@mem debug do something memory wise

@see debug write a message to console

Then these different attributed versions can be disabled. it could be something like

version(debug(see)) = none;

or

static if (hasAttribute(debug, @mem)) disable @mem;

or from the command line or whatever.

What makes this useful is we can easily assign different debug types(could be generalized to other versions(release, etc)) and not have to use version(longer and requires defines of the identifier).



July 24, 2016
On Sunday, 24 July 2016 at 21:33:20 UTC, Gorge Jingale wrote:

> To allow for different debug versions without having to go full blown version().
>
> @mem debug do something memory wise
> @see debug write a message to console

I don't get what would be the benefit.
Currently, you can write that like:

version (debug_mem) {do something memory wise}
version (debug_see) {write a message to console}

In my opinion, saving a few characters here does not get anywhere near a good reason to add language complexity.

Ivan Kazmenko.

July 24, 2016
On Sunday, 24 July 2016 at 23:41:26 UTC, Ivan Kazmenko wrote:
> On Sunday, 24 July 2016 at 21:33:20 UTC, Gorge Jingale wrote:
>
>> To allow for different debug versions without having to go full blown version().
>>
>> @mem debug do something memory wise
>> @see debug write a message to console
>
> I don't get what would be the benefit.
> Currently, you can write that like:
>
> version (debug_mem) {do something memory wise}
> version (debug_see) {write a message to console}
>
> In my opinion, saving a few characters here does not get anywhere near a good reason to add language complexity.
>
> Ivan Kazmenko.

It's not complex to add and it saves more than a few characters, One can append attributes much easier to debug than version. That alone saves about 10 chars each statement, if there is, say 1000 debug statements in a typical smallish app, that's 10000 characters, quite a bit. One also has to consider the extra identifiers to add. That is around 20 chars each. It's also a bit more visual.

It's also easier to remove attributes or change them. If one needs to change all debug attributes @see to @look, that involves about 10 keystrotes. If one has to do this to version, it is about 30.

It already fits in with attributes... no extra complexity their.



July 25, 2016
On Sunday, 24 July 2016 at 21:33:20 UTC, Gorge Jingale wrote:
> To allow for different debug versions without having to go full blown version().

debug(whatever) thingy_here();

dmd -debug=whatever yourfile.d


works today.
July 25, 2016
On Monday, 25 July 2016 at 02:13:34 UTC, Adam D. Ruppe wrote:
> On Sunday, 24 July 2016 at 21:33:20 UTC, Gorge Jingale wrote:
>> To allow for different debug versions without having to go full blown version().
>
> debug(whatever) thingy_here();
>
> dmd -debug=whatever yourfile.d
>
>
> works today.

You can't combine attributes:

@mem @see debug() { prints debug info }

Attributes are useful are they not?

July 25, 2016
On 07/25/2016 04:16 AM, Gorge Jingale wrote:
> On Monday, 25 July 2016 at 02:13:34 UTC, Adam D. Ruppe wrote:
[...]
>> debug(whatever) thingy_here();
[...]
> You can't combine attributes:
>
> @mem @see debug() { prints debug info }

debug(mem) debug(see) { /* ... */ }

Though I'm not sure if the attributes in your example would have an AND or an OR relation. With debug(...) it's AND, of course.