Jump to page: 1 2
Thread overview
UDA for module declaration.
Sep 17, 2014
IgorStepanov
Sep 17, 2014
Orvid King
Sep 17, 2014
Timon Gehr
Sep 17, 2014
Dicebot
Jun 18, 2021
Max Samukha
Jun 18, 2021
Max Samukha
Jun 18, 2021
jmh530
Jun 18, 2021
Max Samukha
Jun 18, 2021
Nicholas Wilson
Jun 18, 2021
Max Samukha
Jun 18, 2021
claptrap
Jun 20, 2021
Max Samukha
Sep 17, 2014
Daniel Kozak
Sep 17, 2014
Johannes Pfau
Sep 17, 2014
ketmar
September 17, 2014
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.
September 17, 2014
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.
September 17, 2014
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.

September 17, 2014
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.
September 17, 2014
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".


September 17, 2014
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.
September 17, 2014
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.
June 18, 2021
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.
June 18, 2021
On Friday, 18 June 2021 at 10:55:58 UTC, Max Samukha wrote:
> turning
turn

June 18, 2021

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

@UDA(42) module test;

struct UDA
{
    int a;
}

pragma(msg, __traits(getAttributes, test)); //prints "tuple(UDA(42))"

void main() {}
« First   ‹ Prev
1 2