14. C Style – naming

14.1. Introduction

.scope: This document describes the conventions for naming in C source code that’s internal in the MPS. See design.mps.interface-c for the corresponding conventions for the public interface.

.readership: This document is intended for anyone working on or with the C source code.

14.2. Capitalization

.capital.macro: Statement-like macros have names consisting of uppercase words separated by underscores, for example ARG_DEFINE_KEY.

.capital.constant: Constants have names consisting of a type (named according to .capital.program or .capital.other), concatenated with an identifier in uppercase with underscores, for example BufferFramePOP_PENDING.

.capital.program: Other names with program scope consist of concatenated title-case words, for example BufferFramePush.

.capital.other: Other names (including function parameters, names with block scope, and names with file scope) consist of concatenated words, the first of which is lowercase and the remainder are uppercase. For example, poolReturn.

14.3. Prefixes

.prefix.program: Any name with program scope must start with the name of the module to which it belongs. For example, names belonging to the buffer module must start with buffer or Buffer or BUFFER. Justification: the C language lacks a namespace facility so the only way to avoid name clashes is for each name to be globally unique.

.prefix.file: Any name with file scope should start with the name of the module to which it belongs. Justification: makes it easy to tell which module a function belongs to; makes it easy to set breakpoints in the debugger.

14.4. Suffixes

.suffix.struct: The type of a structure must be the same as the structure tag, and must consist of the type of the pointer to the structure concatenated with Struct. For example, ArenaStruct.

.suffix.union: The type of a union must be the same as the union tag, and must consist of the type of the pointer to the union concatenated with Union. For example, PageUnion.

.suffix.class: The type of a class (see design.mps.protocol) must end with Class. For example, ArenaClass.

.suffix.method: The type of a method in a class must end with Method. For example, PoolFixMethod.

.suffix.visitor: The type of a visitor function must end with Visitor. For example, TreeVisitor.

.suffix.function: The type of other functions must end with Function. For example, TreeKeyFunction.