Prefixed identifier

Description

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.

Syntax

Table 4.2. Prefixed identifier

ProductionSyntaxLinks
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”

Examples

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

Discussion

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:

[Note]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 Invoice in a Java or C# program is not a guarantee that Invoice is indeed a class or interface, because the programmer could be unaware of the convention 'Class names start with an uppercase letter', he could use another convention or he could just have made a mistake. This problem doesn't exist with Obix's identifier prefixes, because their usage is governed by unbreakable rules. Nevertheless, Obix does of course allow the programmer to use any convention, including Hungarian notation, for identifier suffixes.