www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - UDA for module declaration.

reply "IgorStepanov" <wazar mail.ru> writes:
Why not subj?
D allows annotate with UDA the most of named symbols.
There are three category of named symbols, which cannot be 
annotated: module declarations, function arguments and enum 
members.
Enum members are trivial symbols and annotation possibility for 
them probably does not make sense.
However, annotation unpossibility for module declaration and 
function arguments looks strange.

Why all this talk?
I've created pull request for dmd, which allows UDA for modules 
(https://github.com/D-Programming-Language/dmd/pull/3947) and 
Walter says that I should open topic in n.g. and justify the 
usefulness of this enhancement.

I will give a few examples when UDA can be used for modules and 
arguments:

First example: in ORM framework, like hibernate, I want to add 
posibility to put the module in correspondence to DB scheme:

 Sheme("STOCK") module Stock;

 Entity("WAYBILLS") class Waybill //STOCK.WAYBILLS
{
....
}

 Entity("ITEMS") class Item //STOCK.ITEMS
{
....
}

***************************************************
The second example is a Web MVC framework

 BindModule("forum") module dlang.engine.controllers.forum;

 BindPath("/")
class MainController : AbstractController!(MainController)
{
      BindMethod("/newpost")
     View newPost(Request req,
                   BindParam("tid") int threadID,
                   BindParam("author") string author,
                   BindParam("subj")   string subject,
                   BindParam("msg")    string message)
     {
         ///
         return new TemplateView(model, 
"/dlang/templates/forum/newpost.tmpl");
     }
}

***************************************************
The third example is a my runtime reflection implementation:

I've created generator which walking down the scope symbol, and 
store runtime data, if symbol is annotated with a special UDA.
For example, if class Annotated with  reflect!all, generator will 
save information about all class members into special place. 
However, if local scope symbol is not annotated, information 
about its members will not saved:

 reflect!all class Foo
{
    int a;
    class Bar
    {
       int b;
    }
}
In this example, information for Foo will be saved (that Foo 
contains "a" and class "Bar"), but information about Bar members 
will not be saved.
Thus I want to be able to annotate module that the generator will 
keep information about its members.

Destroy.
Sep 16 2014
next sibling parent reply "Orvid King" <blah38621 gmail.com> writes:
On Wednesday, 17 September 2014 at 00:46:07 UTC, IgorStepanov 
wrote:
 Why not subj?
 D allows annotate with UDA the most of named symbols.
 There are three category of named symbols, which cannot be 
 annotated: module declarations, function arguments and enum 
 members.
 Enum members are trivial symbols and annotation possibility for 
 them probably does not make sense.
 However, annotation unpossibility for module declaration and 
 function arguments looks strange.

 Why all this talk?
 I've created pull request for dmd, which allows UDA for modules 
 (https://github.com/D-Programming-Language/dmd/pull/3947) and 
 Walter says that I should open topic in n.g. and justify the 
 usefulness of this enhancement.

 I will give a few examples when UDA can be used for modules and 
 arguments:

 First example: in ORM framework, like hibernate, I want to add 
 posibility to put the module in correspondence to DB scheme:

  Sheme("STOCK") module Stock;

  Entity("WAYBILLS") class Waybill //STOCK.WAYBILLS
 {
 ....
 }

  Entity("ITEMS") class Item //STOCK.ITEMS
 {
 ....
 }

 ***************************************************
 The second example is a Web MVC framework

  BindModule("forum") module dlang.engine.controllers.forum;

  BindPath("/")
 class MainController : AbstractController!(MainController)
 {
      BindMethod("/newpost")
     View newPost(Request req,
                   BindParam("tid") int threadID,
                   BindParam("author") string author,
                   BindParam("subj")   string subject,
                   BindParam("msg")    string message)
     {
         ///
         return new TemplateView(model, 
 "/dlang/templates/forum/newpost.tmpl");
     }
 }

 ***************************************************
 The third example is a my runtime reflection implementation:

 I've created generator which walking down the scope symbol, and 
 store runtime data, if symbol is annotated with a special UDA.
 For example, if class Annotated with  reflect!all, generator 
 will save information about all class members into special 
 place. However, if local scope symbol is not annotated, 
 information about its members will not saved:

  reflect!all class Foo
 {
    int a;
    class Bar
    {
       int b;
    }
 }
 In this example, information for Foo will be saved (that Foo 
 contains "a" and class "Bar"), but information about Bar 
 members will not be saved.
 Thus I want to be able to annotate module that the generator 
 will keep information about its members.

 Destroy.
UDA's for enum members do make sense, especially in the case of serialization, where you might want a member to be used in your code as one thing, but parsed as a different name, for instance, serializing code where the enum member would be a keyword in D.
Sep 16 2014
parent reply Timon Gehr <timon.gehr gmx.ch> writes:
On 09/17/2014 03:43 AM, Orvid King wrote:
 Why all this talk?
 I've created pull request for dmd, which allows UDA for modules
 (https://github.com/D-Programming-Language/dmd/pull/3947) and Walter
 says that I should open topic in n.g. and justify the usefulness of this
 enhancement.
As far as I am concerned, this does not need any justification, but leaving it out would. A module declaration is as much a declaration as any other declaration and declarations can be annotated with UDAs.
Sep 17 2014
next sibling parent "Dicebot" <public dicebot.lv> writes:
On Wednesday, 17 September 2014 at 12:30:26 UTC, Timon Gehr wrote:
 On 09/17/2014 03:43 AM, Orvid King wrote:
 Why all this talk?
 I've created pull request for dmd, which allows UDA for modules
 (https://github.com/D-Programming-Language/dmd/pull/3947) and 
 Walter
 says that I should open topic in n.g. and justify the 
 usefulness of this
 enhancement.
As far as I am concerned, this does not need any justification, but leaving it out would. A module declaration is as much a declaration as any other declaration and declarations can be annotated with UDAs.
I agree. "Language consistency" sounds like good justification here on its own, the less special cases we have, the better it is for the learning curve.
Sep 17 2014
prev sibling parent reply Max Samukha <maxsamukha gmail.com> writes:
On Wednesday, 17 September 2014 at 12:30:26 UTC, Timon Gehr wrote:
 On 09/17/2014 03:43 AM, Orvid King wrote:
 Why all this talk?
 I've created pull request for dmd, which allows UDA for modules
 (https://github.com/D-Programming-Language/dmd/pull/3947) and 
 Walter
 says that I should open topic in n.g. and justify the 
 usefulness of this
 enhancement.
As far as I am concerned, this does not need any justification, but leaving it out would. A module declaration is as much a declaration as any other declaration and declarations can be annotated with UDAs.
Really. Walter, please note that the lack of this feature makes me turning my codebase into shit right now, not in some indeterminate future.
Jun 18 2021
next sibling parent Max Samukha <maxsamukha gmail.com> writes:
On Friday, 18 June 2021 at 10:55:58 UTC, Max Samukha wrote:
 turning
turn
Jun 18 2021
prev sibling next sibling parent reply jmh530 <john.michael.hall gmail.com> writes:
On Friday, 18 June 2021 at 10:55:58 UTC, Max Samukha wrote:
 [snip]

 Really. Walter, please note that the lack of this feature makes 
 me turning my codebase into shit right now, not in some 
 indeterminate future.
It looks like this PR was merged... ```d UDA(42) module test; struct UDA { int a; } pragma(msg, __traits(getAttributes, test)); //prints "tuple(UDA(42))" void main() {} ```
Jun 18 2021
next sibling parent Dominikus Dittes Scherkl <dominikus scherkl.de> writes:
Is it really necessary to re-animate some seven year old threads?
Jun 18 2021
prev sibling parent Max Samukha <maxsamukha gmail.com> writes:
On Friday, 18 June 2021 at 11:21:34 UTC, jmh530 wrote:

 It looks like this PR was merged...
Yes, my bad. Sorry for the noise.
Jun 18 2021
prev sibling parent reply Nicholas Wilson <iamthewilsonator hotmail.com> writes:
On Friday, 18 June 2021 at 10:55:58 UTC, Max Samukha wrote:
 On Wednesday, 17 September 2014 at 12:30:26 UTC, Timon Gehr 
 wrote:
 On 09/17/2014 03:43 AM, Orvid King wrote:
Really. Walter, please note that the lack of this feature makes me turning my codebase into shit right now, not in some indeterminate future.
The thread you're replying to is like 7 years old. Please try to avoid resurrecting very old threads.
Jun 18 2021
parent reply Max Samukha <maxsamukha gmail.com> writes:
On Friday, 18 June 2021 at 12:09:56 UTC, Nicholas Wilson wrote:
 On Friday, 18 June 2021 at 10:55:58 UTC, Max Samukha wrote:
 On Wednesday, 17 September 2014 at 12:30:26 UTC, Timon Gehr 
 wrote:
 On 09/17/2014 03:43 AM, Orvid King wrote:
Really. Walter, please note that the lack of this feature makes me turning my codebase into shit right now, not in some indeterminate future.
The thread you're replying to is like 7 years old. Please try to avoid resurrecting very old threads.
I will, though I find the dogmatic prejudice against necroposting abhorrent.
Jun 18 2021
parent reply claptrap <clap trap.com> writes:
On Friday, 18 June 2021 at 19:53:51 UTC, Max Samukha wrote:
 On Friday, 18 June 2021 at 12:09:56 UTC, Nicholas Wilson wrote:
 On Friday, 18 June 2021 at 10:55:58 UTC, Max Samukha wrote:
 On Wednesday, 17 September 2014 at 12:30:26 UTC, Timon Gehr 
 wrote:
 On 09/17/2014 03:43 AM, Orvid King wrote:
Really. Walter, please note that the lack of this feature makes me turning my codebase into shit right now, not in some indeterminate future.
The thread you're replying to is like 7 years old. Please try to avoid resurrecting very old threads.
I will, though I find the dogmatic prejudice against necroposting abhorrent.
Are you sure you really mean that? I mean politely asking you not to resurrect old threads is "abhorrent" and not merely just a bit irritating? "Abhorrent" is usually reserved for stuff that will put you in jail for a good few years. Do you think we should lock Nicholas up for a while? Otherwise it was a nice turn of phrase. :)
Jun 18 2021
parent Max Samukha <maxsamukha gmail.com> writes:
On Friday, 18 June 2021 at 21:05:58 UTC, claptrap wrote:

 Are you sure you really mean that? I mean politely asking you 
 not to resurrect old threads is "abhorrent" and not merely just 
 a bit irritating? "Abhorrent" is usually reserved for stuff 
 that will put you in jail for a good few years. Do you think we 
 should lock Nicholas up for a while?
Nicholas is too valuable to be put in jail.
 Otherwise it was a nice turn of phrase. :)
Jun 20 2021
prev sibling next sibling parent Daniel Kozak via Digitalmars-d <digitalmars-d puremagic.com> writes:
V Wed, 17 Sep 2014 00:46:04 +0000
IgorStepanov via Digitalmars-d <digitalmars-d puremagic.com> napsáno:

 Why not subj?
 D allows annotate with UDA the most of named symbols.
 There are three category of named symbols, which cannot be 
 annotated: module declarations, function arguments and enum 
 members.
 Enum members are trivial symbols and annotation possibility for 
 them probably does not make sense.
 However, annotation unpossibility for module declaration and 
 function arguments looks strange.
Month ago I need UDA for module declarations too, so I hack my own version of DMD. It would be fine if this would be in upstream.
Sep 17 2014
prev sibling next sibling parent Johannes Pfau <nospam example.com> writes:
Am Wed, 17 Sep 2014 00:46:04 +0000
schrieb "IgorStepanov" <wazar mail.ru>:

 Why not subj?
 D allows annotate with UDA the most of named symbols.
 There are three category of named symbols, which cannot be 
 annotated: module declarations, function arguments and enum 
 members.
 Enum members are trivial symbols and annotation possibility for 
 them probably does not make sense.
 However, annotation unpossibility for module declaration and 
 function arguments looks strange.
 
 Why all this talk?
 I've created pull request for dmd, which allows UDA for modules 
 (https://github.com/D-Programming-Language/dmd/pull/3947) and 
 Walter says that I should open topic in n.g. and justify the 
 usefulness of this enhancement.
 
In GDC we mosty use UDAs instead of pragmas, so you can do attribute("forceinline") void foo() {}... or forceinline void foo() {}... Obviously there are pragmas which apply to a module (e.g LDC's nomoduleinfo pragma) which we can't represent as an UDA right now. So nomoduleinfo module a; is another possible usecase.
Sep 17 2014
prev sibling parent ketmar via Digitalmars-d <digitalmars-d puremagic.com> writes:
On Wed, 17 Sep 2014 00:46:04 +0000
IgorStepanov via Digitalmars-d <digitalmars-d puremagic.com> wrote:

 Why not subj?
this can be very useful, so i'm sure that it will be called "useless" and "broken".
Sep 17 2014