Skip to content

Latest commit

 

History

History
68 lines (36 loc) · 2.58 KB

03.-formatting.md

File metadata and controls

68 lines (36 loc) · 2.58 KB

03. Formatting

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

3.1 Indentation

Use four spaces for indentation, never tabs. Code blocks should use indented blocks (spaced) rather than curly brackets (braced):

3-1

Except when writing single line expressions like option{a}, my_class{A := b}, etc.

3.2 Spaces

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.

3-2 b

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. 3-3C

3.3 Line Breaks

  • Use a spaced, multiline form to insert a line break. For example:

LINE

  • 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

3.4 Brackets

  • Only use brackets for inheriting class definitions. For example:

my_base_type := class:

  • Do NOT use this styling:

my_base_type := class():

3.5 Avoid Dot-Space Notation

  • Avoid using dot-space ". " notation in place of braces. This makes it visually harder to parse whitespace and is a potential source of confusion.

3-5