Annotations, was Re: Custom attributes C#

Janice Caron caron800 at googlemail.com
Fri Sep 28 01:29:33 PDT 2007


Thank you Daniel, for that wonderful explanation. I've got it now. It
all makes sense.

Seems to me that this is a good idea, because, like templates, it
allows things to be done in libraries and user code which would
otherwise have to be done in the language. It makes the langage
/simpler/, not more complicated, but at the same time it lets you
express more. That's gotta be a win-win all round.

It would mean that we could deprecate "deprecated" (ironically), and
replace it with an annotation. Ditto pragmas.

xxxxx said it wouldn't be much use without runtime reflection. I
disagree. Compile-time annotations would still be useful. As noted
above, compile-time annotations would allow us to get rid of
"deprecated" (and also "unittest" and "pragma"). How can getting rid
of keywords not be a good thing? It would also allow for some pretty
cunning templates, assuming that templates could specialise on the
presence (or absence) of an annotation. Runtime reflection can come
later (if that's that way D goes).

However, I would like to say this, before the ink dries on the paper -
I don't like either the Java syntax or the C# syntax. I've said before
that (in my opinion) there are things much worse than keyword bloat,
and among those worse things I would include operator bloat and
punctuation bloat. (Operator bloat is just a special case of
punctuation bloat). You can argue that too many keywords pollutes the
namespace, but to give too many different meanings to too many
combinations of punctuation marks is way, way worse. I don't want to
see @*%!? and the like in source code, and have to learn what it
means. Walter got it absolutely right when he introduced the cast()
syntax - it's /totally/ readable. So, here, I believe, is a
circumstance where a keyword is desirable, and preferable to any
combination of punctuation marks. Compare:

    @big @fat int f(int n); // Java style

    [big, fat] int f(int n); // C# style

    metadata(big,fat)
    int f(int n); // One possible alternative

    keywords(big,fat)
    int f(int n); // Another possible alternative

    pragma(big,fat)
    int f(int n); // A third alternative

My third suggestion re-uses the already reserved word "pragma", so no
new reserved words would have to be introduced, so even keyword bloat
is avoided.



More information about the Digitalmars-d mailing list