Attributes
Divider

Java has a convention for its "Java Beans", GUI elements in the form of classes, where the name of a function helps specify what it does.  Another piece of code can then come along and scan the class--which it generally doesn't know anything about--using "reflection", a method of retrieving information about a class at runtime using RTTI.  It uses the form of the name of certain functions to determine purpose.  I didn't like this because it forces a particular naming convention on programmers, something I think a language standard should not do.  My original solution as an alternative was to allow "tags" to be applied to members of a class (and, incidentally, to entire classes), which were just flags indicated by identifiers preceding the name of each function or variable.  However, I couldn't quite decide how it should be implemented, and was uncomfortable that its use was too limited and not very general.

Then C# came along and presented a more general solution: "attributes".   This feature allows you to associate not just flags, but entire classes, with class members.  In other words, you create an attribute class, and the fields of that class store information you want associated with particular members of other classes.  And attributes can be applied not only to class members, but classes themselves, function arguments, enumerations, and enumeration constants.  This is a way of extending the amount of declarative information for program elements beyond what is in the base language.

Some attribute classes in C# have special meanings to the compiler, which affect compilation.  I didn't like this, because I think it's generally best to make an obvious separation between hard-coded language features, and user-defined add-ons.   However, using attributes provides better integration with program elements than the Compile Pragma statement I'd included in QDL.

This section describes QDL attributes, which differ in some ways from C# attributes.

attributes: attribute-set+
attribute-set: [<single-attribute>]
single-attribute: [namespace::]*attribute-type-identifier [initialize-spec]

initialize-spec is in the same format used for variable declarations (although array initialization syntax is not applicable).  Syntax is described under variable lists.  The initialize-spec gives one of two things: arguments to the attribute's constructor (in brackets), or a set of initializers for the fields of the class (in curly braces).

Here is an example that demonstrates assigning attributes to various program elements:

[AttributeForEnum] Enum Fruits:
	[Source ("Bush")] Raspberry,
	[Source ("Tree")] Apricot,
	[Source ("Vine")] Grape,
End Enum;
[AttributeForClass] Class MyClass:
	[Attribute With Arguments (1, "2", 3.0)]
	Function FuncWithAttributes([Arg Attribute Demo] X, Y: Char);
	[XAndY, Have, Four, Attributes] X, Y: Integer;
	[Repeated Attribute(1)][Repeated Attribute(2)]
	Function AnotherFunction ();
End Class;

There are several things to notice here:

 

Table of Contents Qwertie's Site/Mirror
Next
Previous
Hosted by www.Geocities.ws

1