The Wayback Machine - https://web.archive.org/web/20161008155209/http://modula-2.info/m2r10/pmwiki.php/Recommendations/NameConvention

Modula-2 Reloaded

A Modern Typesafe & Literate Programming Notation

Site

Project

Specification

Implementation

Recommendations

Reference

Articles

Examples


Work in Progress

Future Outlook

Needs Updating

Wastebasket

Wiki Manual

edit SideBar

Name Convention

Definitions

Lowercase
 AllLower : LowercaseLetter+ ;
 factorial

Capitalized
 Capitalized : CapitalLetter LowercaseLetter+ Digit* ;
 Complex   String80

Boldface Case
 BoldfaceCase : CapitalLetter+ Digit* ;
 BITSET   BITSET32

Smalltalk Case
 SmalltalkCase : LowercaseLetter ( LowercaseLetter | Digit )* TitleCase ;
 valueForKey

Title Case
 TitleCase : ( CapitalLetter ( LowercaseLetter | Digit )* )* ;
 BufferSize

Well Known Acronym
 WellKnownAcronym : 'ASCII' | 'BCD' | 'IEEE754' | 'ISO646' | 'UTF8' | 'UTF16' ;
 ASCII

Snake Case
 SnakeCase : LowercaseLetter+ ( '_' ( LowercaseLetter+ | Digit+ ) )* ;
 copy_n_bytes

Ada Case
 AdaCase : CapitalLetter LowercaseLetter+ ( '_' ( CapitalLetter LowercaseLetter+ | Digit+ ) )* ;
 Copy_N_Bytes

C Macro Case
 CMacroCase : CapitalLetter+ ( '_' ( CapitalLetter+ | Digit+ ) )* ;
 MAX_ALLOC_SIZE

Studly Caps
 StudlyCaps : ( CapitalLetter | LowercaseLetter ) ( CapitalLetter | LowercaseLetter | Digit )* ;
 vI32xMNcT QHzuT5Ltw

Presentation

Names in boldface case are considered to be lowercase boldface. Although these names are written in all-capital letters in plain text source code

 FOR index, value IN array DO WRITE(value) END;

they may be rendered in lowercase boldface by syntax aware source code editors and in published source code on the web or in print.

 for index, value in array do write(value) end;

However, names that are recognised as well known acronyms are not considered to be lowercase boldface. Such well known acronyms may then be rendered in all-capital letters even when other names in all-capital letters are rendered in in lowercase boldface.

 definition module ASCII;

Naming Identifiers in Modula-2 Programs and Libraries

This name convention has been derived from observed common use in Pascal, Modula-2 and Oberon literature and in standard libraries shipped with numerous compilers. It is recommended that this name convention is followed in all user defined programs, libraries, blueprints and templates.

Reserved Names

The following names are reserved either for future reserved words or for use by the standard library:

Names to Avoid

  • reserved names should never be instituted as identifiers in user defined programs, libraries, blueprints and templates.
  • a sole capital letter O should never be instituted as an identifier because it is easily confused for digit 0.
  • a sole lowercase letter l should never be instituted as an identifier because it is easily confused for digit 1.

Module Identifiers

Module identifiers always start with a capital letter, are generally in title case and describe nouns.

 DEFINITION MODULE RealMath;

The standard library implements numerous ADTs that are practically part of the language. Their module identifiers are often in boldface case.

 DEFINITION MODULE COMPLEX;

In some cases, the standard library may define a module identifier that represents a well known acronym.

 DEFINITION MODULE ASCII;

Constant Identifiers

Identifiers of math constants are always in all-lowercase.

 CONST pi = 3.1415926;

All other constant identifiers are always in title case and describe nouns or conditions.

 CONST BufferSize = 1000; SupportsResize = FALSE;

Since enumerated values are constants, their identifiers follow the convention for constants.

 TYPE Colour = ( Red, Green, Blue );

Type Identifiers

Type identifiers are always in title case and describe nouns.

 TYPE PriorityQueue = OPAQUE;

Variable Identifiers

Variable identifiers that represent regular procedures are always in title case and describe verbs or actions.

 TYPE WriteStrProc = PROCEDURE ( File, ARRAY OF CHAR );
 VAR WriteStr : WriteStrProc;

All other variable identifiers are always in all-lowercase or Smalltalk case and describe nouns or conditions.

 VAR index, sourceIndex, targetIndex : CARDINAL; isWellOrdered = TRUE;

Field Identifiers

Field identifiers follow the same convention as variable identifiers.

 TYPE Triangle = RECORD
   p1, p2, p3 : Point;
   Draw : PROCEDURE ( Triangle )
 END;

Procedure Identifiers

Regular procedure identifiers are always in title case and describe verbs or actions.

 PROCEDURE WriteString ( CONST str : ARRAY OF CHAR );

Function Identifiers

Identifiers of math functions are always in all-lowercase.

 PROCEDURE factorial ( n : LONGCARD ) : LONGCARD;

All other function identifiers are in all-lowercase or Smalltalk case and describe nouns or conditions.

 PROCEDURE valueForKey ( dict : Dictionary; key : KeyType ) : ValueType;

Parameter Identifiers

Identifiers of formal parameters are always in all-lowercase or Smalltalk case.

 PROCEDURE Insert ( VAR targetStr : ARRAY OF CHAR; atIndex : CARDINAL; ch : CHAR );

Blueprint Identifiers

Blueprint identifiers are always in title case and describe nouns. Standard library blueprints are prefixed with the word Proto.

 BLUEPRINT ProtoDictionary;

Template Identifiers

Template identifiers are always in title case and use the plural form of nouns. Identifiers of placeholders within templates are either in title case and describe verbs or actions, or they are in all-lowercase or in Smalltalk case and describe nouns or conditions.

 GENLIB BigInteger FROM Integers FOR bitwidth = 256;

Import Aggregator Identifiers

Identifiers of import aggregators always follow the convention for module identifiers. Some may be plural words prefixed with Std.

 DEFINITION MODULE StdIntegers;
 IMPORT INTEGER16+, INTEGER32+, INTEGER64+, INTEGER128+;
 END StdIntegers.

IO Library Identifiers

Identifiers of IO extension libraries always follow the letter case convention for module identifiers. The name of an IO library is composed by appending a suffix to the identifier of the type for which the library provides IO facilities. Suffix IO is appended to compose the name of the base IO library and suffix ArrayIO is appended to compose the name of the array IO library. In place of all-caps type identifiers, capitalised equivalents are used.

 IMPORT COMPLEX, ComplexIO, ComplexArrayIO;
 IMPORT Foo, FooIO, FooArrayIO;

Math Library Identifiers

Identifiers of math extension libraries always follow the letter case convention for module identifiers. The name of a math library is composed by appending suffix Math to the identifier of the type for which the library provides math facilities. In place of all-caps type identifiers, capitalised equivalents are used.

 IMPORT COMPLEX, ComplexMath;
 IMPORT Vector, VectorMath;

Foreign API Identifiers

Identifiers of foreign API functions and foreign API modules always follow the name convention of the foreign API. In addition to lowercase, all-caps, Smalltalk case and title case, such identifiers may use snake case, Ada case, C macro case or studly caps and they may contain dollar signs.

 DEFINITION MODULE foolib <*FFI="C"*>;
 CONST MAX_BAR = 42;
 PROCEDURE baz_bam_boo ( i : INTEGER ) : INTEGER;
 END foolib.

Filename Convention

Program Files

The filename of a program module is composed by appending file suffix .mod to the module identifier.

 FooTool.mod

Definition Files

The filename of a definition part of a library module is composed by appending file suffix .def to the module identifier.

 FooLib.def

Implementation Files

The filename of an implementation part of a library module is composed by appending file suffix .mod to the module identifier.

 FooLib.mod

Blueprint Files

The filename of a blueprint is composed by appending file suffix .def to the blueprint identifier.

 ProtoFoo.def

Template Files

The filename of a template is composed by appending file suffix .gen.def or .gen.mod to the template identifier.

 Integers.gen.def
 Integers.gen.mod

On platforms where the filesystem does not support this convention, template filenames may simply be suffixed with .def and .mod instead.