Skip to content

Language Specification (E) : Naming Convention

Benjamin Kowarsch edited this page Sep 10, 2020 · 3 revisions

Naming Convention

Module Identifiers

Module identifiers always start with a capital letter.

DEFINITION MODULE Foobar;

Multi-word module identifiers are in title case.

DEFINITION MODULE FileSystem;

A module identifier that coincides with a widely used acronym may be all-uppercase. However, as a general rule, the institution of all-uppercase identifiers should be avoided to prevent name conflicts with future reserved words and pervasive identifiers.

DEFINITION MODULE ASCII;

The identifier of a module that follows the module-as-a-type paradigm should be a singular noun, describing the type that the module provides.

DEFINITION MODULE String;

TYPE String = OPAQUE POINTER;

The identifier of a module that follows the module-as-a-manager paradigm should generally also be a singular noun, describing the management service the module provides.

DEFINITION MODULE Console;

However, in some cases it may be preferable for a module that follows the module-as-a-manager paradigm to use an identifier that is a plural noun, if that better describes its service.

DEFINITION MODULE CompilerOptions;

The use of single-letter module identifiers is strictly prohibited except in unit tests.

Constant Identifiers

Constant identifiers always start with a capital letter.

CONST Separator = '/';

Multi-word constant identifiers are in title case.

CONST BufferSize = 4096;

In some cases a constant identifier that coincides with a common acronym may be all-uppercase. However, as a general rule of thumb, the definition and declaration of all-uppercase identifiers should preferably be avoided.

CONST NUL = 0u0; (* ASCII NUL *)

The enumerated values of enumeration types are constants and follow the naming convention for constants.

TYPE Status = ( Success, Failure );

The use of single-letter constant identifiers is strictly prohibited except in unit tests.

Type Identifiers

Type identifiers always start with a capital letter.

TYPE Key = CARDINAL;

Multi-word type identifiers are in title case.

TYPE RegexStatus = RECORD ( Status ) code : RegexStatusCode END;

A type identifier that coincides with a widely used acronym may be all-uppercase. However, as a general rule, the institution of all-uppercase identifiers should be avoided.

TYPE AST = OPAQUE POINTER; (* Abstract Syntax Tree *)

The identifier of the primary type provided by a module that follows the module-as-a-type paradigm should match the module identifier verbatim.

DEFINITION MODULE String;

TYPE String = OPAQUE POINTER;

The use of single-letter identifiers for public types is strictly prohibited except in unit tests.

Variable Identifiers

Variable identifiers always start with a lowercase letter.

VAR ch : CHAR;

Multi-word variable identifiers are always in camel case.

VAR sourceIndex, targetIndex : LONGCARD;

The use of single-letter variable identifiers should be avoided, except for modelling math formulas.

Record Field Identifiers

Record field identifiers follow the convention for variable identifiers.

Procedure Identifiers

Regular procedure identifiers always start with a capital letter.

PROCEDURE Write ( ch : CHAR );

Multi-word regular procedure identifiers are in title case.

PROCEDURE WriteChars ( str : ARRAY OF CHAR );

The use of single-letter regular procedure identifiers is strictly prohibited except in unit tests.

Function Identifiers

Function procedure identifiers always start with a lowercase letter.

PROCEDURE length ( str : String ) : LONGCARD;

Multi-word function procedure identifiers are in camel case.

PROCEDURE isQuotable ( ch : CHAR ) : BOOLEAN;

The use of single-letter function procedure identifiers is strictly prohibited except in unit tests.

Formal Parameter Identifiers

Formal parameter identifiers follow the convention for variable identifiers.

The use of single-letter formal parameter identifiers should generally be avoided, but is permissible in math functions where parameters n and m denote unsigned integers, i and j denote signed integers and r denotes a real number.

PROCEDURE log2 ( n : CARDINAL ) : CARDINAL;
Clone this wiki locally