It is important to stay consistent with formatting throughout your codebase. This makes the code easier to read and understand for yourself and other developers. Choose a formatting style that works for the project.
As an example of staying consistent, you could choose one of the following spacing formats and use it throughout the codebase:
MyVariable : int = 5
MyVariable:int = 5
Use four spaces for indentation, never tabs. Code blocks should use indented blocks (spaced) rather than curly brackets (braced):
Except when writing single line expressions like option{a}
, my_class{A := b}
, etc.
Use spaces around operators, unless it makes sense to keep the code compact for its context. Add braces to explicitly define the order of operations.
MyNumber := 4 + (2 * (a + b))
Don’t add spaces at the beginnings and ends of brackets. Multiple expressions inside brackets should be separated by a single space.
Keep identifier and type together; add a space around the assignment =
operator. Add a space around type definitions and constant initialization operators (:=
).
MyVariable:int = 5
MyVariable := 5
my_type := class
Follow the same recommendations for brackets, identifiers, and types spacing for function signatures.
- Use a spaced, multiline form to insert a line break. For example:
- DO NOT use a single line, example:
MyTransform := transform{Translation := vector3{X := 100.0, Y := 200.0, Z := 300.0}, Rotation := rotation{...}}
- Define enums in spaced, multiline form if they need per-enumeration comments or if you need to insert a line break.
enum:
Red, # Desc1
Blue, # Desc2
- Only use brackets for inheriting class definitions. For example:
my_base_type := class:
- Do NOT use this styling:
my_base_type := class():
- Avoid using dot-space ". " notation in place of braces. This makes it visually harder to parse whitespace and is a potential source of confusion.