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
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 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