digitalmars.D - What have you done with UDAs?
- weaselcat (2/2) Jun 22 2015 I never seem to use them for anything, has anyone else done
- Dragos Carp (2/4) Jun 22 2015 https://github.com/linkrope/dunit#user-defined-attributes
- Ilya Yaroshenko (5/7) Jun 22 2015 UDAs are very useful for IO libraries. You can find them in
- Nick Sabalausky (8/14) Jun 22 2015 Yea, I really like vibe's use of them. I've worked with web tools before...
- Alex Parrill (15/17) Jun 22 2015 I'm writing a program that can accept subcommands via either the
- Dmitry Olshansky (18/35) Jun 23 2015 And I thought that I might be the only one doing this ;)
- Alex Parrill (8/30) Jun 23 2015 Not yet; its ATM a bit coupled with the application I'm writing.
- Andrei Alexandrescu (3/5) Jun 23 2015 Could you please submit these as bug reports at http://issues.dlang.org
- Atila Neves (9/11) Jun 22 2015 I use them all the time:
- Kapps (31/33) Jun 22 2015 Like several others, I use them for generating command line
- Vladimir Panteleev (3/8) Jun 23 2015 Same here:
- Tofu Ninja (4/6) Jun 22 2015 I am currently writing a ui system that defines the majority of
- Rikki Cattermole (3/9) Jun 22 2015 Got a repo yet?
- Tofu Ninja (4/11) Jun 23 2015 Not yet, it's integrated into a game engine I am working on and
- extrawurst (4/6) Jun 22 2015 They are great!
- Jacob Carlborg (8/10) Jun 22 2015 Serialization:
- Jonas Drewsen (8/10) Jun 22 2015 I use a few in the deadcode editor e.g.:
- Jonas Drewsen (11/21) Jun 25 2015 Just remembered, I also use it for the animation system to tell
- Brian Schott (11/13) Jun 22 2015 Semi-hijacking this thread:
- extrawurst (2/15) Jun 23 2015 LGTM! Finally these are added to phobos. Thanks!
- Mathias Lang via Digitalmars-d (9/30) Jun 23 2015 I use them all the time in vibe.web.rest. It allows to override the
- E.S. Quinn (5/7) Jun 22 2015 I use UDAs in my project to generate GTK UI for editing
- Basile Burg (25/27) Jun 22 2015 I use them to annotate the setter/getter pairs in classes. Two
- Manu via Digitalmars-d (17/19) Jun 22 2015 I've used them for attributing struct members with some information
- Rikki Cattermole (4/6) Jun 22 2015 Dvorm and Cmsed used them.
- "Marc =?UTF-8?B?U2Now7x0eiI=?= <schuetzm gmx.net> (16/16) Jun 23 2015 I use them in a simple MongoDB-based ORM, not (yet?) publically
- ponce (5/7) Jun 23 2015 I've used them along with reflection to describe OpenGL vertex
- John Colvin (3/5) Jun 23 2015 Amongst other things, I use them in PydMagic to mark functions to
- Random D-user (13/15) Jun 23 2015 What a cool thread.
I never seem to use them for anything, has anyone else done anything interesting with them?
Jun 22 2015
On Monday, 22 June 2015 at 19:09:40 UTC, weaselcat wrote:I never seem to use them for anything, has anyone else done anything interesting with them?https://github.com/linkrope/dunit#user-defined-attributes
Jun 22 2015
On Monday, 22 June 2015 at 19:09:40 UTC, weaselcat wrote:I never seem to use them for anything, has anyone else done anything interesting with them?UDAs are very useful for IO libraries. You can find them in vibe.d web server: http://d.readthedocs.org/en/latest/examples.html#service (see last method)
Jun 22 2015
On 06/22/2015 03:18 PM, Ilya Yaroshenko wrote:On Monday, 22 June 2015 at 19:09:40 UTC, weaselcat wrote:Yea, I really like vibe's use of them. I've worked with web tools before that inferred URLs and querty string value names and visibility from the names/visibility of classes/functions/arguments. But I never liked that approach, how it conflates internal names/visibility with external interface. Too much implicit magic, and too much leaking of internals. UDA'a maintain the convenience of that approach, but keep a nice clean separation.I never seem to use them for anything, has anyone else done anything interesting with them?UDAs are very useful for IO libraries. You can find them in vibe.d web server: http://d.readthedocs.org/en/latest/examples.html#service (see last method)
Jun 22 2015
On Monday, 22 June 2015 at 19:09:40 UTC, weaselcat wrote:I never seem to use them for anything, has anyone else done anything interesting with them?I'm writing a program that can accept subcommands via either the command line (ex. `prog mycmd 1 2`) or via a shell. I represent each command as a function, use UDAs to store the help text and if they can be ran from the command line or shell. The command list, full help text, and command dispatcher is generated at compile time via templates, CTFE, and static foreach. An example command: ("<nanoseconds>") // arguments ("Sets the amount of time to increment the clock on each frame.") // description ShellOnly // can't be ran from command line int cmd_set_time_per_frame(string[] args) { // ... }
Jun 22 2015
On 22-Jun-2015 22:21, Alex Parrill wrote:On Monday, 22 June 2015 at 19:09:40 UTC, weaselcat wrote:And I thought that I might be the only one doing this ;) Declarative command-line handling is much more scalable approach for swiss-army knife command-line tools.I never seem to use them for anything, has anyone else done anything interesting with them?I'm writing a program that can accept subcommands via either the command line (ex. `prog mycmd 1 2`) or via a shell. I represent each command as a function, use UDAs to store the help text and if they can be ran from the command line or shell. The command list, full help text, and command dispatcher is generated at compile time via templates, CTFE, and static foreach.An example command: ("<nanoseconds>") // arguments ("Sets the amount of time to increment the clock on each frame.") // description ShellOnly // can't be ran from command line int cmd_set_time_per_frame(string[] args) { // ... }Awesome. Is it open-sourced? How about handling argument conversion automatically (via to! and/or custom functions)? Say : ("<num1> <num2>") CmdName("plus") void add(int a, int b) { writelen(a+b); } To be automagically callable like: ./prog plus 2 4 -- Dmitry Olshansky
Jun 23 2015
On Tuesday, 23 June 2015 at 14:52:30 UTC, Dmitry Olshansky wrote:Not yet; its ATM a bit coupled with the application I'm writing. Specifying types with the arguments is definitely feasible, but I haven't gotten around to writing it yet. You could also possibly specify flag arguments (--foo) by specifying default parameters. (somewhat related: std.getopts is kinda bad; you can't get help text without successfully parsing arguments and `required` breaks `--help`)An example command: ("<nanoseconds>") // arguments ("Sets the amount of time to increment the clock on each frame.") // description ShellOnly // can't be ran from command line int cmd_set_time_per_frame(string[] args) { // ... }Awesome. Is it open-sourced? How about handling argument conversion automatically (via to! and/or custom functions)? Say : ("<num1> <num2>") CmdName("plus") void add(int a, int b) { writelen(a+b); } To be automagically callable like: ./prog plus 2 4
Jun 23 2015
On 6/23/15 8:05 AM, Alex Parrill wrote:(somewhat related: std.getopts is kinda bad; you can't get help text without successfully parsing arguments and `required` breaks `--help`)Could you please submit these as bug reports at http://issues.dlang.org - thanks! -- Andrei
Jun 23 2015
On Monday, 22 June 2015 at 19:09:40 UTC, weaselcat wrote:I never seem to use them for anything, has anyone else done anything interesting with them?I use them all the time: https://github.com/atilaneves/unit-threaded https://github.com/atilaneves/cerealed https://github.com/atilaneves/unencumbered https://github.com/D-Programming-Language/phobos/pull/3207 (std.experimental.testing proposal) Compile-time reflection seems to be my D hammer. Atila
Jun 22 2015
On Monday, 22 June 2015 at 19:09:40 UTC, weaselcat wrote:I never seem to use them for anything, has anyone else done anything interesting with them?Like several others, I use them for generating command line interfaces to set variables / invoke methods using reflection. For example https://shardsoft.com/stash/projects/SHARD/repos/dap/browse/source D Asset Pipeline Converts assets into an intermediate post-processed format more efficiently loaded at runtime. Commands: [--init]: Initializes the folder structure for a dap repository using a Content subdirectory in this folder. [--clean]: Cleans the output directory, removing all built assets. [-h|--help]: Displays the help string. [-a|--add]: Adds the given raw asset to the asset store using the default processor and default settings. [-r|--remove]: Removes the asset with the specified qualified name from the asset store. [-l|--list]: Lists all assets currently stored. [-b|--build]: Builds all dirty assets using current settings. [-i|--inspect]: Shows all properties of the given asset. [-o|--open]: Opens the given asset in an external editor. [-m|--modify]: Modifies a property of a processor on an asset, or the processor used to build the asset. Options: [--input-folder]: The folder that assets should be read from and settings stored in. Default: Content/Input [--output-folder]: The folder that generated assets should be saved to. Default: Content/Output [--log-level]: The minimum severity for a message to be logged. Default: info
Jun 22 2015
On Monday, 22 June 2015 at 19:36:59 UTC, Kapps wrote:On Monday, 22 June 2015 at 19:09:40 UTC, weaselcat wrote:Same here: http://blog.thecybershadow.net/2014/08/05/ae-utils-funopt/I never seem to use them for anything, has anyone else done anything interesting with them?Like several others, I use them for generating command line interfaces to set variables / invoke methods using reflection.
Jun 23 2015
On Monday, 22 June 2015 at 19:09:40 UTC, weaselcat wrote:I never seem to use them for anything, has anyone else done anything interesting with them?I am currently writing a ui system that defines the majority of the layout in a dsl. The ui element types are defined in D code and I use uda's to mark which fields can be accesses by the dsl.
Jun 22 2015
On 23/06/2015 7:43 a.m., Tofu Ninja wrote:On Monday, 22 June 2015 at 19:09:40 UTC, weaselcat wrote:Got a repo yet? Would be interested in reading more about it.I never seem to use them for anything, has anyone else done anything interesting with them?I am currently writing a ui system that defines the majority of the layout in a dsl. The ui element types are defined in D code and I use uda's to mark which fields can be accesses by the dsl.
Jun 22 2015
On Tuesday, 23 June 2015 at 06:43:21 UTC, Rikki Cattermole wrote:Not yet, it's integrated into a game engine I am working on and it's in the early stages of usability, will probably split it off once it gets more mature.I am currently writing a ui system that defines the majority of the layout in a dsl. The ui element types are defined in D code and I use uda's to mark which fields can be accesses by the dsl.Got a repo yet? Would be interested in reading more about it.
Jun 23 2015
On Monday, 22 June 2015 at 19:09:40 UTC, weaselcat wrote:I never seem to use them for anything, has anyone else done anything interesting with them?They are great! see my post about one use case: http://extrawurst.github.io/dlang/metaprogramming/imgui/2015/05/28/dlang-annotations.html
Jun 22 2015
On 22/06/15 21:09, weaselcat wrote:I never seem to use them for anything, has anyone else done anything interesting with them?Serialization: https://github.com/jacob-carlborg/orange/blob/master/tests/NonSerialized.d#L25-L39 Selectors in D/Objective-C. It's actually a compiler recognized UDA, but still a UDA: https://github.com/jacob-carlborg/dmd/blob/dobjc_instance_methods/test/runnable/objc_call.d#L7 -- /Jacob Carlborg
Jun 22 2015
On Monday, 22 June 2015 at 19:09:40 UTC, weaselcat wrote:I never seem to use them for anything, has anyone else done anything interesting with them?I use a few in the deadcode editor e.g.: Function can be called by a menu entry: MenuItem("Edit/Copy") Function can be called by a shortcut: Shortcut("<shift> + <f10>") Function should run in a fiber when called: InFiber
Jun 22 2015
On Monday, 22 June 2015 at 20:29:15 UTC, Jonas Drewsen wrote:On Monday, 22 June 2015 at 19:09:40 UTC, weaselcat wrote:Just remembered, I also use it for the animation system to tell what can be animated (modified by proxy) e.g: Bindable() { CSSPositionMix _position; CSSScaleMix _width; CSSScaleMix _height; CSSVisibility _visibility; ... }I never seem to use them for anything, has anyone else done anything interesting with them?I use a few in the deadcode editor e.g.: Function can be called by a menu entry: MenuItem("Edit/Copy") Function can be called by a shortcut: Shortcut("<shift> + <f10>") Function should run in a fiber when called: InFiber
Jun 25 2015
On Monday, 22 June 2015 at 19:09:40 UTC, weaselcat wrote:I never seem to use them for anything, has anyone else done anything interesting with them?Semi-hijacking this thread: I recently made a few pull requests to get better support for UDAs into Phobos. https://github.com/D-Programming-Language/phobos/pull/3356 https://github.com/D-Programming-Language/phobos/pull/3421 https://github.com/D-Programming-Language/phobos/pull/3363 The last of the three is stuck because nobody's looking at it. Can those of you who use UDAs take a look at these and confirm that I haven't made any dumb mistakes before the 2.068 release goes out with them included?
Jun 22 2015
On Monday, 22 June 2015 at 20:57:59 UTC, Brian Schott wrote:On Monday, 22 June 2015 at 19:09:40 UTC, weaselcat wrote:LGTM! Finally these are added to phobos. Thanks!I never seem to use them for anything, has anyone else done anything interesting with them?Semi-hijacking this thread: I recently made a few pull requests to get better support for UDAs into Phobos. https://github.com/D-Programming-Language/phobos/pull/3356 https://github.com/D-Programming-Language/phobos/pull/3421 https://github.com/D-Programming-Language/phobos/pull/3363 The last of the three is stuck because nobody's looking at it. Can those of you who use UDAs take a look at these and confirm that I haven't made any dumb mistakes before the 2.068 release goes out with them included?
Jun 23 2015
I use them all the time in vibe.web.rest. It allows to override the defaults (e.g. by default `getfoo` maps to `GET /foo`): https://github.com/Geod24/vibe.d/blob/ea061223ab96d5acdc004e9369f904c5e25ec8d0/source/vibe/web/rest.d#L60-L66 I actually really, really miss attributed parameters. Obviously it's possible to emulate it ( https://github.com/Geod24/vibe.d/blob/ea061223ab96d5acdc004e9369f904c5e25ec8d0/source/vibe/web/rest.d#L169-L182) but it isn't as nice... 2015-06-23 9:04 GMT+02:00 extrawurst via Digitalmars-d < digitalmars-d puremagic.com>:On Monday, 22 June 2015 at 20:57:59 UTC, Brian Schott wrote:On Monday, 22 June 2015 at 19:09:40 UTC, weaselcat wrote:LGTM! Finally these are added to phobos. Thanks!I never seem to use them for anything, has anyone else done anything interesting with them?Semi-hijacking this thread: I recently made a few pull requests to get better support for UDAs into Phobos. https://github.com/D-Programming-Language/phobos/pull/3356 https://github.com/D-Programming-Language/phobos/pull/3421 https://github.com/D-Programming-Language/phobos/pull/3363 The last of the three is stuck because nobody's looking at it. Can those of you who use UDAs take a look at these and confirm that I haven't made any dumb mistakes before the 2.068 release goes out with them included?
Jun 23 2015
On Monday, 22 June 2015 at 19:09:40 UTC, weaselcat wrote:I never seem to use them for anything, has anyone else done anything interesting with them?I use UDAs in my project to generate GTK UI for editing components in my ECS. (For things like marking string fields as filenames, or giving numeric fields upper and lower bounds) https://dl.dropboxusercontent.com/u/187059/Screenshot-sarah%20-%20Entity%20Editor.png
Jun 22 2015
On Monday, 22 June 2015 at 19:09:40 UTC, weaselcat wrote:I never seem to use them for anything, has anyone else done anything interesting with them?I use them to annotate the setter/getter pairs in classes. Two analyzers look for them to automatically create what i call a "property descriptor". https://github.com/BBasile/iz/blob/master/import/iz/properties.d#L362 Property descriptors are then used to - bind/synchronize several properties together. - serialize or deserialize classes. This is directly inspired by Pascal's "published" property. All the type information system is replaced with UDA and static analysis: Pascal: --- published property myProp: integer read getMyProp write setMyProp; --- D2 equivalent: --- SetGet private int _field; // solution 1: use directly the field Set void myProp(int value){} // solution 2: use explicit accessors. Get int myProp(){return _field;} --- The Annotations work very well with virtual methods. For example the most derivated (overriden) anotated Set/ Get is always took by the analyzer, like expected.
Jun 22 2015
On 23 June 2015 at 05:09, weaselcat via Digitalmars-d <digitalmars-d puremagic.com> wrote:I never seem to use them for anything, has anyone else done anything interesting with them?I've used them for attributing struct members with some information about their semantic meaning, which allows systems to automatically bind those structs to useful functions. For instance, I have attributed color structs with information about the D3D or OpenGL format spec's that represent, I have done the same with vertex data, expressing the semantic meaning of the elements in the vertex struct, so they can be bound automatically to the appropriate shader inputs. I've used it for control over serialisation of data in structs. I've used it to tag information to struct fields that are to be exported to editor environments, and control how those properties should be represented in editors (pretty-names, type of editor (select box, color picker, etc). I've used them for giving information to automated bindings for scripting systems. Particularly, I use them to tell automated systems to consider or ignore certain things.
Jun 22 2015
On 23/06/2015 7:09 a.m., weaselcat wrote:I never seem to use them for anything, has anyone else done anything interesting with them?Dvorm and Cmsed used them. Both for routing and data models. (They are both sunsetted right now btw)
Jun 22 2015
I use them in a simple MongoDB-based ORM, not (yet?) publically available. Usage is like this: Collection("my.model") struct MyModel { Field Required Index BsonObjectID foreignKey; Field string someOptionalString; Field Required int[] someRequiredArray; Field Validate!(a => a % 2 != 0) int onlyOddIntegers; Field ValidEmail string email; mixin ORM; }
Jun 23 2015
On Monday, 22 June 2015 at 19:09:40 UTC, weaselcat wrote:I never seem to use them for anything, has anyone else done anything interesting with them?I've used them along with reflection to describe OpenGL vertex formats from a struct. https://github.com/d-gamedev-team/gfm/blob/master/opengl/gfm/opengl/vertex.d#L25 From this thread it seems UDA are quite successful.
Jun 23 2015
On Monday, 22 June 2015 at 19:09:40 UTC, weaselcat wrote:I never seem to use them for anything, has anyone else done anything interesting with them?Amongst other things, I use them in PydMagic to mark functions to be wrapped by pyd and exposed to the python.
Jun 23 2015
On Monday, 22 June 2015 at 19:09:40 UTC, weaselcat wrote:I never seem to use them for anything, has anyone else done anything interesting with them?What a cool thread. This is very valuable info for new(ish) d users. It's often the case for language features that they are just branded cool. But that's just a statement (and you go 'uhm, ok.'). What people usually need is some kind of proof or demonstration why they are useful and how to solve problems with them (which you can usually only get through experience). Wouldn't it be great if there was a wiki page of cool d-features where each feature would have a list like this showcasing what people have done with it? You could then just point people to this wiki page to get a practical view of why d is great.
Jun 23 2015