Tag (programming)
Encyclopedia
In programming, a tag is an argument
Parameter (computer science)
In computer programming, a parameter is a special kind of variable, used in a subroutine to refer to one of the pieces of data provided as input to the subroutine. These pieces of data are called arguments...

 to a subroutine
Subroutine
In computer science, a subroutine is a portion of code within a larger program that performs a specific task and is relatively independent of the remaining code....

 that determines other arguments passed to it, which is used as a way to pass indefinite number of tagged parameters to the subroutine; notably, tags are used for a number of system calls in AmigaOS
AmigaOS
AmigaOS is the default native operating system of the Amiga personal computer. It was developed first by Commodore International, and initially introduced in 1985 with the Amiga 1000...

 v2.0 and onwards.

In AmigaOS

In earlier versions of AmigaOS
AmigaOS
AmigaOS is the default native operating system of the Amiga personal computer. It was developed first by Commodore International, and initially introduced in 1985 with the Amiga 1000...

, if a system call required setting a large number of parameters, instead of passing them as function arguments, the function would require a pointer to a structure
Data structure
In computer science, a data structure is a particular way of storing and organizing data in a computer so that it can be used efficiently.Different kinds of data structures are suited to different kinds of applications, and some are highly specialized to specific tasks...

 that holds the arguments (for example, intuition.library's OpenWindow required struct NewWindow with 17 different parameters). Tags were introduced in AmigaOS 2.0 because:
A number of third-party
Third-party software component
In computer programming, a third-party software component is a reusable software component developed to be either freely distributed or sold by an entity other than the original vendor of the development platform...

 software libraries for AmigaOS also use tags extensively.

Example

AmigaOS 1.3 AmigaOS 2.0+

struct Window *wnd;

struct NewWindow nw = {
        10, 10,
        100, 100,
        0, 1,
        IDCMP_CLOSEWINDOW,
        WFLG_SIZEGADGET >
WFLG_DRAGBAR |
WFLG_DEPTHGADGET |
WFLG_CLOSEGADGET |
WFLG_ACTIVATE,
        NULL, NULL,
        "WikiWindow",
        NULL, NULL,
        0, 0,
        640, 400,
        WBENCHSCREEN
};

wnd = OpenWindow(&nw);

struct Window *wnd;

wnd = OpenWindowTags(NULL,
        WA_Left, 10, WA_Top, 10,
        WA_Width, 100, WA_Height, 100,
        WA_IDCMP, IDCMP_CLOSEWINDOW,
        WA_Flags,
WFLG_SIZEGADGET >
WFLG_DRAGBAR |
WFLG_DEPTHGADGET |
WFLG_CLOSEGADGET |
WFLG_ACTIVATE,
        WA_Title, "WikiWindow",
        WA_PubScreenName, "Workbench",
        TAG_DONE );


Note how the code without tags is obscure (for example, 0, 1 define window colors) while the code with tags is self-documenting. Note also that fewer parameters have to be defined with tags than are in the structure, as OpenWindowTags will fall back to default parameters.

Implementation

AmigaOS provides functions for tag handling in its utility.library.

In general

An advantage of tags is that they ease the work with default arguments
Default (computer science)
A default, in computer science, refers to a setting or value automatically assigned to a software application, computer program or device, outside of user intervention. Such settings are also called presets, especially for electronic devices...

 since the programmer doesn't have to specify them or their substitutes. From this follows another advantage, ease of achieving of both forward
Forward compatibility
Forward compatibility or upward compatibility is a compatibility concept for systems design, as e.g. backward compatibility. Forward compatibility aims at the ability of a design to gracefully accept input intended for later versions of itself...

 and backward compatibility
Backward compatibility
In the context of telecommunications and computing, a device or technology is said to be backward or downward compatible if it can work with input generated by an older device...

 with external libraries: a program written for an older version of the library will work with a newer one, since the newer library will simply set all the parameters not provided by the program to their default values; and a program written for a newer version of the library will still work with the older version, since the older library will simply pay no attention to the newly-introduced tags.

A disadvantage of tags is that their processing is slower than simply reading data from a structure
Data structure
In computer science, a data structure is a particular way of storing and organizing data in a computer so that it can be used efficiently.Different kinds of data structures are suited to different kinds of applications, and some are highly specialized to specific tasks...

 or the stack
Stack (data structure)
In computer science, a stack is a last in, first out abstract data type and linear data structure. A stack can have any abstract data type as an element, but is characterized by only three fundamental operations: push, pop and stack top. The push operation adds a new item to the top of the stack,...

. Additionally, compile time
Compile time
In computer science, compile time refers to either the operations performed by a compiler , programming language requirements that must be met by source code for it to be successfully compiled , or properties of the program that can be reasoned about at compile time.The operations performed at...

 type checking is lost.

External links

The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK