Skip to content

Code style

Florine W. Dekker edited this page Jun 7, 2023 · 10 revisions

The scripts used to generate the dumps are written in a special form of Object Pascal, and a Python wrapper manages the post-processing. This article details the style guide used for these scripts.

Python

See PEP 8.

Pascal

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.

Documentation and comments

  • 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.
  • Comments
    • Inline comments should be preceded by exactly two spaces.
    • Inline comments should not be terminated by a period.
    • Avoid using block comments, except to document function signatures.

Global variables

  • Avoid using global variables.
  • Names of global variables should be prefixed with the originating unit's name and an underscore.

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.

Parentheses

Always add parentheses when defining or invoking a procedure, even if it takes no arguments.

Spacing

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

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.