A prefixed identifier is an identifier that is prefixed by any number of letters followed by a prefix terminator which is an underscore.
The part following the prefix terminator is called the prefixed identifier's suffix.
Prefixed identifiers are used to group (classify) identifiers. The prefix defines the group the prefixed identifier belongs to.
In Obix identifier prefixes are used to specify the kind of software element. For example, all type identifiers start with ty_, and all factory identifiers start with fa_. See Obix identifier prefixes for a complete list of all prefixes used in Obix.
Table 4.2. Prefixed identifier
| Production | Syntax | Links |
|---|---|---|
prefixed_identifier |
identifier_prefix identifier_prefix_terminator identifier
| the section called “Prefixed identifier” |
identifier_prefix |
letter *
| |
identifier_prefix_terminator |
"_"
| |
identifier |
letter ( letter | digit | "_" ) *
| the section called “Simple identifier” |
Example 4.2. Prefixed identifiers
type identifiers: ty_customer ty_indexed_list ty_coffee_machine_2 attribute identifiers: a_color a_first_name command identifiers: co_append co_remove_last
Identifier prefixes are optional to write in Obix source code, as long as there is no ambiguity. The compiler automatically prefixes identifiers, if the prefix is not explicitly typed in the source code. For example, typing
type ty_customer attribute a_name type:ty_string end command co_show_sales end end
can more easily be written as:
type customer attribute name type:string end command show_sales end end
However, prefixed identifiers can considerably increase the understandability of source code. Whenever the kind of software element cannot be easily discerned by the human reader, it is recommended to type the prefix, even if it is not required to be typed. For example, instead of reading
invoice.last_number = number
reading
se_invoice.a_last_number = i_number
is more understandable, because we immediately see that an input argument (i_) is assigned to an attribute (a_) of a service (se_).
Prefixed identifiers have other advantages:
We can use the same suffix for different identifiers having the same or a related role, but a different scope.
A typical example is an assignment instruction in a creator, where an input argument is assigned to an attribute. Writing:
a_address = i_address
clearly indicates the assignment of an input argument (i_) to an attribute (a_). There is no need for a different identifier suffix for the input argument.
Another frequent case is a type/factory identifier pair. For example, ty_customer denotes the type, and fa_customer the factory.
The performance of the compiler and other tools can be increased, because the parsing of a prefixed identifier immediately tells the parser the kind of software element.
In case of a new keyword added to the language, no identifier suffix needs to be changed in the source code. In the worst case, prefixes have to be added at places where ambiguity arises.
![]() | Note |
|---|---|
There is an important difference between Hungarian notation used by programmers in different languages, and prefixed identifiers in Obix: Hungarian notation is based on conventions, whereas prefixed identifiers in Obix are based on rules which are built into the language. The problem with conventions is that no tool (i.e. the compiler) can detect violations. For example, the identifier |