Scope
All rules are applicable to local, global, member, parameter, class variables or constants. Furthermore the naming convention described here can be applied to classes, name spaces, functions and database column names. Especially database column names should comply to the same convention.
Descriptive
Use (long) descriptive variable names. This improves the readability of the code and prevents ambiguity. Also prevent abbreviations with the exception of abbreviations or acronyms that are commonly known and more widely used then the written out phrase (for example HTTP or SQL).
CamelCase
Use CamelCase variable names to combine compound words such that each word or abbreviation begins with a capital letter. For words, abbreviations or acronyms that are commonly entirely upper case (for example PDF or HTML), only capitalize the first letter.
Reference information
When a value of a variable is relative to a reference value and different reference values could be applicable, then use it to extend the descriptive variable name
separated by a single underscore ("_"). For example use Time_Utc
to distinct from Time_Local
. When in doubt if
the reference value is necessary, then add it.
Units of measurement
Include units of measurement in the variable name when applicable. To enable automatic validation of unit arithmetic, we use the following strict convention:
- Extend the variable name with the unit separated by a double underscore:
Name__Unit
orName_Reference__Unit
. - Use standard (SI or SI derived) symbols / abbreviations for the units in the correct case. If no standard symbol is know use a commonly used abbreviation. Examples: "m" for meters, "Mb" for Megabit, "deg" for degrees.
- For multiplication of units concatenate the units without a separator: "ms" for meter × second, "kgh" for kilogram × hour.
- For division of units concatenate the units with a single underscore ("_") separator: "m_s" for meter ÷ second, .
- Exponentiation of a base unit with a constant exponent is done by suffixing the base unit with the exponent: "m2" for square meter.
- To combine units for multidimensional data, separate the units with double underscores ("__"): "m_s__deg" for meter per second and degrees.
Loop counter variables
Loop counter variables should be named Index
or something more descriptive when applicable. For nested loops you can suffix with a number or
add an extra name (RowIndex
and ColumnIndex
) to distinguish between loop variables.
Examples
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// Descriptive CamelCase:
ShipType: TShipType;
WebSiteDailyStatisticsTable: TTableWebSiteModule;
StandardReportDocumentCompiler: TDocumentToHtmlCompiler;
HtmlWriter: THtmlDocumentWriter;
RoutePdfResponse: THttpPdfResponse;
// Reference information:
TimeStamp_Utc: TDateTime;
WaterLevel_Msl: TFloatingPoint64;
// Units of measurement:
Width__m: TFloatingPoint64; // Width in meter [m]
Surface__m2: TFloatingPoint64; // Surface in square meter [m^2]
Speed__m_s: TFloatingPoint64; // Speed in meter per second [m]/[s]
Velocity__m_s__deg: TFloatingPoint64Point; // Two dimensional velocity vector with speed in meter per second and angle in degrees [m]/[s] and [°]
Acceleration__m_s2: TFloatingPoint64; // Acceleration in meter per second squared [m]/[s^2]
EnergyDensity__m2s_rad: TFloatingPoint64; // Energy density in square meter second per radians [m^2][s]/[rad]
TimeLocation__s__km: T2dFloatingPoint64Point; // Two dimensional time location point with time in second and location in kilometer [s] and [km]
// Arithmetic with units:
Surface__m2 := Width__m * Length__m;
Speed__kn := (Speed__m_s / 3.6) * 1.852;
EnergyDensity__m2s_rad := EnergyDensity__m2_Hzdeg * 180 / Pi;