Skip to content

Code style

Felix W. Dekker edited this page Sep 27, 2020 · 14 revisions

The scripts used to generate the dumps are written in a special form of Object Pascal. This article details the style guide used for these scripts.

Indentation

  • Indent using 4 spaces.
  • Use a continuation indent of 4 spaces.
  • When breaking up a line at an operator, place the operator on the second line.

Line length

  • Lines should be limited to 120 columns.
  • Always end the file with a trailing newline.

Spacing

  • Write spaces around operators.
  • Do not write a space before : or ,, and write one space after : or ,.

Capitalisation

  • Units and types should be in Pascal case.
    • This includes Integer, String, and Boolean.
  • Functions and procedures should be in dromedary case.
  • Variables and parameters should be in dromedary case.
  • Keywords (e.g. result, break, and, true, false) should be in lowercase.
    • The only exception is NULL, which should be in uppercase.

Statements

  • Never place multiple statements on one line.
  • Declare a function or procedure's first variable on the same line as the var.
  • Do not place unnecessary parentheses around conditions.
  • Always use compound statements for if, for, while, repeats, case, and try.
  • Use a semicolon for the last statement in a compound statement.
  • Place the begin keyword on the same line as the condition.
  • Place the else on the same line as the preceding if's end.

Functions and procedures

  • Always add parentheses when invoking a statement, even if it takes no arguments.

Global variables

  • Avoid using global variables.
  • Global variables that should not be accessed by other units should be prefixed with the unit's name and an underscore.

Documentation

  • Each function/procedure must have a Javadoc-ish comment block above it.
  • Parameter descriptions should be aligned horizontally.
  • Parameter names and their descriptions should be separated by at least two spaces.

Clone this wiki locally