Documentation

Arx Code Style

Arx Code Style

Use these conventions when writing Arx source for libraries, applications, examples, and tests. The guide draws on PEP 8 and follows Arx's lexical syntax and Douki docstrings. Apply the conventions to new and edited code. Keep formatting changes to unrelated code out of feature and fix diffs.

Layout

Module order and imports

Start with the module docstring. Follow it with imports, then module constants and type aliases, and then definitions. Leave one blank line between the docstring and the imports, and between groups of imports. Group imports in this order.

  1. Arx standard library and explicit builtin imports
  2. External package imports
  3. Imports from the current project

Use the name-first import name from module form for imported symbols. Import related names from the same module on one line when they fit, using parentheses for a group. Use absolute module paths across package boundaries. Use relative imports for nearby modules in the same package when that makes the relationship clear. See Modules for the supported forms.

Names and visibility

Use Convention Example
Modules and packages Short lowercase names, with underscores where useful file_tools
Functions, methods, variables, fields, and parameters snake_case read_score, max_score
Classes and named types PascalCase ScoreLimit
Module constants Uppercase words separated by underscores MAX_SCORE

Use self as the first parameter of instance methods. Use Arx visibility modifiers to express access, such as -> private :: i64 for a private function. Use a double-underscore name only for an established language protocol, such as __init__.

Spacing and expressions

Comments and Douki docstrings

Begin every source file with a Douki module docstring at line one, column one. Place class, function, and method docstrings first in their bodies. Use triple backticks around the YAML and include a title. Document what callers need to know, such as accepted inputs, units, ownership, and errors. See Docstrings for the supported fields and placement rules.

Write comments with # and a following space. Prefer a comment immediately above the relevant code for reasoning or constraints that a reader might miss. When a short inline comment helps, separate it from the statement by two spaces.

Complete example

```
title: Score limits
summary: Apply an inclusive upper bound to a score.
```

import math from stdlib

MAX_SCORE: const :: i64 = 10


class Score:
  ```
  title: Score value
  ```
  value: private :: i64

  fn __init__(self, value: i64) -> none:
    self.value = value

  fn bounded(self, limit: i64 = MAX_SCORE) -> i64:
    ```
    title: Clamp the score to the inclusive range from zero to the limit.
    parameters:
      limit: Nonnegative upper bound.
    returns: The score after clamping.
    ```
    return math.clamp(self.value, 0, limit)


fn reached_limit(
  score: Score,
  limit: i64
) -> bool:
  return score.bounded(limit=limit) == limit


fn main() -> i32:
  score: Score = Score(15)
  assert reached_limit(score, limit=MAX_SCORE)
  return 0

Search documentation

Type to search.