|
Site Project Specification Implementation Recommendations Reference Articles Examples Work in Progress Future Outlook Needs Updating Wastebasket Wiki Manual |
Name ConventionDefinitionsLowercaseAllLower : LowercaseLetter+ ; factorial CapitalizedCapitalized : CapitalLetter LowercaseLetter+ Digit* ; Complex String80 Boldface CaseBoldfaceCase : CapitalLetter+ Digit* ; BITSET BITSET32 Smalltalk CaseSmalltalkCase : LowercaseLetter ( LowercaseLetter | Digit )* TitleCase ; valueForKey Title CaseTitleCase : ( CapitalLetter ( LowercaseLetter | Digit )* )* ; BufferSize Well Known AcronymWellKnownAcronym : 'ASCII' | 'BCD' | 'IEEE754' | 'ISO646' | 'UTF8' | 'UTF16' ; ASCII Snake CaseSnakeCase : LowercaseLetter+ ( '_' ( LowercaseLetter+ | Digit+ ) )* ; copy_n_bytes Ada CaseAdaCase : CapitalLetter LowercaseLetter+ ( '_' ( CapitalLetter LowercaseLetter+ | Digit+ ) )* ; Copy_N_Bytes C Macro CaseCMacroCase : CapitalLetter+ ( '_' ( CapitalLetter+ | Digit+ ) )* ; MAX_ALLOC_SIZE Studly CapsStudlyCaps : ( CapitalLetter | LowercaseLetter ) ( CapitalLetter | LowercaseLetter | Digit )* ; vI32xMNcT QHzuT5Ltw PresentationNames 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 LibrariesThis 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 NamesThe following names are reserved either for future reserved words or for use by the standard library:
Names to Avoid
Module IdentifiersModule 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 IdentifiersIdentifiers 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 IdentifiersType identifiers are always in title case and describe nouns. TYPE PriorityQueue = OPAQUE; Variable IdentifiersVariable 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 IdentifiersField identifiers follow the same convention as variable identifiers. TYPE Triangle = RECORD p1, p2, p3 : Point; Draw : PROCEDURE ( Triangle ) END; Procedure IdentifiersRegular procedure identifiers are always in title case and describe verbs or actions. PROCEDURE WriteString ( CONST str : ARRAY OF CHAR ); Function IdentifiersIdentifiers 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 IdentifiersIdentifiers of formal parameters are always in all-lowercase or Smalltalk case. PROCEDURE Insert ( VAR targetStr : ARRAY OF CHAR; atIndex : CARDINAL; ch : CHAR ); Blueprint IdentifiersBlueprint identifiers are always in title case and describe nouns. Standard library blueprints are prefixed with the word BLUEPRINT ProtoDictionary; Template IdentifiersTemplate 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 IdentifiersIdentifiers of import aggregators always follow the convention for module identifiers. Some may be plural words prefixed with DEFINITION MODULE StdIntegers; IMPORT INTEGER16+, INTEGER32+, INTEGER64+, INTEGER128+; END StdIntegers. IO Library IdentifiersIdentifiers 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 IMPORT COMPLEX, ComplexIO, ComplexArrayIO; IMPORT Foo, FooIO, FooArrayIO; Math Library IdentifiersIdentifiers of math extension libraries always follow the letter case convention for module identifiers. The name of a math library is composed by appending suffix IMPORT COMPLEX, ComplexMath; IMPORT Vector, VectorMath; Foreign API IdentifiersIdentifiers 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 ConventionProgram FilesThe filename of a program module is composed by appending file suffix FooTool.mod Definition FilesThe filename of a definition part of a library module is composed by appending file suffix FooLib.def Implementation FilesThe filename of an implementation part of a library module is composed by appending file suffix FooLib.mod Blueprint FilesThe filename of a blueprint is composed by appending file suffix ProtoFoo.def Template FilesThe filename of a template is composed by appending file suffix Integers.gen.def Integers.gen.mod On platforms where the filesystem does not support this convention, template filenames may simply be suffixed with |