Custom attributes (again)

Manu turkeyman at gmail.com
Thu Apr 5 05:00:08 PDT 2012


I just want to add more real-world experience to the controversy.
I'm finding myself needing to use custom attributes almost every day.

I have numerous systems that need to scan the module for things marked
accordingly to automate bindings to their respective systems.

This is my current list of attributes I want to mark things with:
  Export to game engine
  Export to script language
  Import from game engine
  ** Import from script language (tentative, I'm sure I'll need it in a few
more days)
  Expose to editor (with additional properties; description, edit type, etc)
  Serialise (load/save game)
  Replay serialisation (a different kind of serialisation that works with
different data sets)

And others I've encountered in passing that I can't recall right now.

As you can imagine, any attempt to 'work around' the lack of an attribute
system, ie, (ab)using enums, etc as have been suggested, leads to a big
mess in the context of all these requirements.
Management of such lists of stuff in disconnected places in code is time
consuming, thoroughly annoying, error-prone, difficult to maintain, and
leaves programmers with the bitter taste of C++.
Alternatively, wrapping virtually every single declaration made in mixin()
and declaring everything as strings is even more nasty, and the contrast
between mixin() declarations and 'normal' declarations looks completely
stupid. (Totally unreadable + difficult to understand, breaks intellisense,
code completion, syntax hilighting, etc... ie, unusable)

Does anyone have a *realistic* suggestion for emulating custom attributes?
Something that doesn't have any(/many) of the side effects I mention?
I haven't come up with anything that's acceptable yet.

If not, I assert that D absolutely needs a custom attribute system. For us
here, this will enable D the single biggest advantage over using C++ in the
same context that I've identified so far.
D's meta-programming is amazing, but sadly, proving pointless to me right
now without being able to mark stuff appropriately. All the meta magic is
hovering just out of my grasp, due to the fact I have no way to indicate
what items should involve with what systems.
Currently, I have to maintain big registry tables of junk that must be
amended/updated any time anyone adds/changes anything... and I'm feeling
rather embarrassed when I tell the other non-D programmers that they just
need to update this table here... and here... and make sure that's in sync
too before their stuff will just 'magically' work ;)

C# and Java both have attributes, following these established design
patterns, I don't think there should be any mystery over how they should be
implemented.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20120405/fb179541/attachment.html>


More information about the Digitalmars-d mailing list