-
Notifications
You must be signed in to change notification settings - Fork 6
Code style
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.
See PEP 8 and the Black Code Style.
To correctly format Python code, use Black.
To install Black, ensure you have uv installed (see Generating dumps) and run uv run black . to fix formatting in all Python files.
- Lines must be at most 120 columns long.
- Files must end with a trailing newline.
- Units and types must be written in Pascal case (e.g.
PascalCase).- This includes
Integer,String, andBoolean.
- This includes
- Functions/procedures must be written in dromedary case (e.g.
dromedaryCase). - Variables and parameters must be written in dromedary case (e.g.
dromedaryCase). - Keywords (e.g.
result,break,and,true,false) must be written in lowercase.-
Exception:
NULLmust be written in uppercase.
-
Exception:
-
Documentation blocks (
(** ... *))- must be placed above each function/procedure.
- must start with a one-sentence description of the function/procedure.
- may contain more detailed prose after the first sentence.
-
may describe parameters in more detail with
@paramtags. - must align parameter descriptions horizontally.
- must separate parameter name from parameter description by at least two spaces.
-
may describe the output in more detail with a
@returntag. -
must use a line containing only an indented
*to separate (1) first line, (2) prose, and (3) tags. - must not separate tags with any lines.
Examples
-
Bad: (starts with
(*, is broken by empty line, does not align parameter descriptions)(* * Returns the sum of [number] and [anotherNumber]. * @param number the number to sum * @param anotherNumber the other number to sum * @return the sum of [number] and [anotherNumber] *) function sum(number: Integer; anotherNumber: Integer): Integer;
-
Bad: (does not separate first line from prose, and adds line between tags)
(** * Returns the sum of [number] and [anotherNumber]. * The inputs are integers, and so is the output. * * @param number the number to sum * @param anotherNumber the other number to sum * * @return the sum of [number] and [anotherNumber] *) function sum(number: Integer; anotherNumber: Integer): Integer;
-
Good: (though excessively verbose)
(** * Returns the sum of [number] and [anotherNumber]. * * @param number the number to sum * @param anotherNumber the other number to sum * @return the sum of [number] and [anotherNumber] *) function sum(number: Integer; anotherNumber: Integer): Integer;
-
Comments
- Super-block comments (
(*** ... **)) may be used to separate large groups of functions/procedures. - Block comments (
(* ... *)) should be avoided, except to document function/procedure signatures. - Inline comments must be preceded by exactly two spaces.
- Inline comments must not be terminated by a period.
- Exception: Inline comments spanning multiple lines may be terminated by a period if it contains multiple proper sentences.
- Super-block comments (
-
Lines must be indented in increments of 4 spaces.
-
Lines must use a continuation indent of 4 spaces, except when no ambiguity exists.
Examples
-
Bad:
foo( bar );
-
Bad:
foo( bar, baz + qux ); -
Good:
foo( bar ); -
Good:
foo( bar, baz + qux ); -
Good: (no ambiguity)
foo( baz + qux );
-
Bad:
-
When a statement is split at an operator, the operator must be placed at the end of the first line.
Examples
-
Bad:
result := foo() + bar();
-
Good:
result := foo() + bar();
-
Bad:
- Operators must be surrounded by whitespace on both ends.
- Symbols
:and,must not be preceded by whitespace. - Symbols
:and,must be followed by whitespace.
- Lines must not contain multiple statements.
- The first variable of a function/procedure must be placed on the same line as the
varkeyword. - Conditions must not be surrounded by unnecessary parentheses.
-
Bad:
if (foo = 'bar') then begin baz(); end -
Good:
if foo = 'bar' then begin baz(); end
-
Bad:
-
if,for,while,repeats,case, andtrymust always use compound blocks (begin ... end).-
Bad:
if condition then foo(); -
Good:
if condition then begin foo(); end;
-
Bad:
- The last statement in a compound statement must be followed by a semicolon.
- The
beginkeyword must be placed on the same line as the condition. - The
beginkeyword must not be followed directly by a semicolon. - The
elsekeyword must be placed on the same line as the precedingif'send. - An
if-then-elsechain must be terminated by a semicolon. -
ifblocks may be written as a one-liner when its contents are short and simple and there is noelseblock. A one-lineifblock must still use a compound block.
Procedure definitions and invocations must use parentheses, even if there are no arguments.
- Global variables should be avoided whenever possible.
- Global variables must be prefixed with the originating unit's name and an underscore.